WordPress.org

Ready to get started?Download WordPress

Forums

Get attachment url from the media manager (5 posts)

  1. mendezki
    Member
    Posted 5 years ago #

    I can't seem to find the url of an attachment in the media library.

    An option would of course be for me to *finally* create an attachment.php for my theme, since that's where the 'view' link points, but I was hoping someone might be able to point me to a plugin/hack that would just show the url of the attachment in the 'Edit Media' screen?

  2. mendezki
    Member
    Posted 5 years ago #

    Ok so I cobbled some code together to make it work.
    It's no beauty, but shows the url of the attachment in the Edit Media subpanel.

    function mp_show_media_url($string, $post) {
    
    		$id = $post->ID;
    		$image_url = wp_get_attachment_url($post->ID);
    		$string = "<span id='mp-showurl-$id'>$image_url - $where_are_we isthis $media_php_url</span></td></tr>\n\t\t<tr><td>";
    
    		// Ugly stuff going on down here, I guess:
    
    		$media_php_url = get_bloginfo('url').'/wp-admin/media.php?action=edit&attachment_id='.$post->ID; // get the media.php url
    		$where_are_we = 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; // where are we now
    
    		if (strcmp($media_php_url, $where_are_we) == 0) {
    		return $string;
    		}else{
    		return;
    		}
    }
    
    add_filter('media_meta', 'mp_show_media_url', 10, 2);

    Don't know how to get it to only show in the edit media screen accessed from the Media Library and not in the pop-up when editing a post, so did some crude stuff for that.
    Any hints are welcome :)

  3. raliste
    Member
    Posted 5 years ago #

    what about just (wp 2.6)+:

    if(strpos($_SERVER['REQUEST_URI'], 'inline') !== false)

    ?

  4. rosschapman
    Member
    Posted 5 years ago #

    edit the media.php file located in wp-admin/includes and change the line

    $filename = basename($post->guid);

    to

    $filename = $post->guid;

    now go into your media library, click edit on the desired file, and there's your URL!

  5. elanio
    Member
    Posted 4 years ago #

    Alternatively you may want to place your code in the file:

    wp-admin/edit-attachment-rows.php

    after line 94:
    place the following:
    echo "<BR /><span class='$action'>URL: $post->guid</span>";

    So it looks like this:

    <td <?php echo $attributes ?>><strong><a href="<?php echo get_edit_post_link( $post->ID ); ?>" title="<?php echo attribute_escape(sprintf(__('Edit "%s"'), $att_title)); ?>"><?php echo $att_title; ?></a></strong><br />
    		<?php echo strtoupper(preg_replace('/^.*?\.(\w+)$/', '$1', get_attached_file($post->ID))); ?>
    		<p>
    		<?php
    		$actions = array();
    		if ( current_user_can('edit_post', $post->ID) )
    			$actions['edit'] = '<a href="' . get_edit_post_link($post->ID, true) . '">' . __('Edit') . '</a>';
    		if ( current_user_can('delete_post', $post->ID) )
    			$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("post.php?action=delete&post=$post->ID", 'delete-post_' . $post->ID) . "' onclick=\"if ( confirm('" . js_escape(sprintf( ('draft' == $post->post_status) ? __("You are about to delete this attachment '%s'\n  'Cancel' to stop, 'OK' to delete.") : __("You are about to delete this attachment '%s'\n  'Cancel' to stop, 'OK' to delete."), $post->post_title )) . "') ) { return true;}return false;\">" . __('Delete') . "</a>";
    		$actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . attribute_escape(sprintf(__('View "%s"'), $title)) . '" rel="permalink">' . __('View') . '</a>';
    		$action_count = count($actions);
    		$i = 0;
    		echo '<div class="row-actions">';
    		foreach ( $actions as $action => $link ) {
    			++$i;
    			( $i == $action_count ) ? $sep = '' : $sep = ' | ';
    			echo "<span class='$action'>$link$sep</span>";
    		}
    		echo "<BR /><span class='$action'>URL:  $post->guid</span>";
    		echo '</div>';
    		?></p></td>

    This will show the URL underneath
    'Edit | Delete | New'
    on Roll over.

Topic Closed

This topic has been closed to new replies.

About this Topic