@@ -106,15 +106,29 @@ function custom_columns_cpt( $columns ) {
106106 function form_filter_dropdown () {
107107 global $ pagenow ;
108108
109- if ( 'edit.php ' != $ pagenow ) {
109+ $ allowed = array ("wplf-submission " ); // show filter on these post types (currently only one?)
110+ $ allowed = apply_filters ("wplf-dropdown-filter " , $ allowed );
111+ $ post_type = get_query_var ("post_type " );
112+
113+ if ( 'edit.php ' != $ pagenow || !in_array ($ post_type , $ allowed )) {
110114 return ;
111115 }
112116
113- // TODO: put this in a transient
114- $ forms = get_posts ( array (
115- 'post_per_page ' => '-1 ' ,
116- 'post_type ' => 'wplf-form ' ,
117- ) );
117+ $ transient = get_transient ("wplf-form-filter " );
118+
119+ if ($ transient ){
120+ $ forms = $ transient ;
121+ }
122+
123+ else {
124+ $ forms = get_posts ( array (
125+ 'post_per_page ' => '-1 ' ,
126+ 'post_type ' => 'wplf-form ' ,
127+ ) );
128+
129+ set_transient ("wplf-form-filter " , $ forms , 15 * MINUTE_IN_SECONDS );
130+ }
131+
118132?>
119133<label for="filter-by-form" class="screen-reader-text">Filter by form</label>
120134<select name="form" id="filter-by-form">
@@ -170,6 +184,7 @@ function metabox_submission() {
170184 global $ post ;
171185 $ postmeta = get_post_meta ( $ post ->ID );
172186 $ fields = array_keys ( $ postmeta );
187+ $ home_path = get_home_path ();
173188?>
174189<p>
175190 <table class="wp-list-table widefat striped">
@@ -182,9 +197,26 @@ function metabox_submission() {
182197 <tbody>
183198 <?php foreach ( $ fields as $ field ) : ?>
184199 <?php if ( '_ ' != $ field [0 ] ) : ?>
185- <?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+ ?>
186218 <tr>
187- <th><strong><?php echo $ field ; ?> </strong></th>
219+ <th><strong><?php echo $ field ; ?> </strong> <?php echo $ possible_link ; ?> </th>
188220 <?php if ( strlen ( $ value ) > 60 || strpos ( $ value , "\n" ) ) : ?>
189221 <td><textarea style="width:100%" readonly><?php echo esc_textarea ( $ value ); ?> </textarea></td>
190222 <?php else : ?>
@@ -201,4 +233,3 @@ function metabox_submission() {
201233}
202234
203235endif ;
204-
0 commit comments