@@ -184,6 +184,7 @@ function metabox_submission() {
184184 global $ post ;
185185 $ postmeta = get_post_meta ( $ post ->ID );
186186 $ fields = array_keys ( $ postmeta );
187+ $ home_path = get_home_path ();
187188?>
188189<p>
189190 <table class="wp-list-table widefat striped">
@@ -196,9 +197,26 @@ function metabox_submission() {
196197 <tbody>
197198 <?php foreach ( $ fields as $ field ) : ?>
198199 <?php if ( '_ ' != $ field [0 ] ) : ?>
199- <?php $ value = $ postmeta [ $ field ][0 ]; ?>
200+ <?php
201+ $ value = $ postmeta [ $ field ][0 ];
202+ $ possible_link = '' ;
203+ $ attachment_url = wp_get_attachment_url ( $ value ); // get_edit_post_link returns something awkward.
204+
205+ // Maybe add a filter for target="_blank"? Wouldn't enable by default.
206+
207+ if ( $ attachment_url ) {
208+ // If this is true, $value was a valid attachment_id.
209+ // Caveat: if user enters a numeric value here, it could be interpreted as attachment.
210+ $ attachment_url = get_edit_post_link ($ value );
211+ $ possible_link = "<a href=' $ attachment_url' style='float: right;'>Edit attachment</a> " ;
212+ } elseif ( file_exists ( $ home_path . substr ( $ value , 1 ) ) ) {
213+ // This is bit less ambiguous. Check if there's a file, and if there is, get link for it.
214+ $ attachment_url = get_home_url () . $ value ;
215+ $ possible_link = "<a href=' $ attachment_url' style='float: right;'>Open file</a> " ;
216+ }
217+ ?>
200218 <tr>
201- <th><strong><?php echo $ field ; ?> </strong></th>
219+ <th><strong><?php echo $ field ; ?> </strong> <?php echo $ possible_link ; ?> </th>
202220 <?php if ( strlen ( $ value ) > 60 || strpos ( $ value , "\n" ) ) : ?>
203221 <td><textarea style="width:100%" readonly><?php echo esc_textarea ( $ value ); ?> </textarea></td>
204222 <?php else : ?>
0 commit comments