[wp-trac] [WordPress Trac] #22180: Add attachments to "existing content" area in link dialog

WordPress Trac noreply at wordpress.org
Thu May 2 12:31:15 UTC 2019


#22180: Add attachments to "existing content" area in link dialog
-----------------------------+-------------------------
 Reporter:  cgrymala         |       Owner:  (none)
     Type:  feature request  |      Status:  closed
 Priority:  normal           |   Milestone:
Component:  Editor           |     Version:  3.4
 Severity:  normal           |  Resolution:  worksforme
 Keywords:                   |     Focuses:
-----------------------------+-------------------------

Comment (by pomegranate):

 For anyone else trying to accomplish this, there was a small error in one
 of the filters above (missing the argument count = 2 in `wp_link_query`).
 This worked for me:

 {{{#!php
 // include 'inherit' post statuses so attachments are returned
 add_filter( 'wp_link_query_args', 'my_modify_link_query_args' );
 function my_modify_link_query_args( $query ) {
         $query['post_status'] = (array) $query['post_status'];
         $query['post_status'][] = 'inherit';

         return $query;
 }

 // Link to media file URL instead of attachment page
 add_filter( 'wp_link_query', 'my_modify_link_query_results', 10, 2 );
 function my_modify_link_query_results( $results, $query ) {
         foreach ( $results as $key => $result ) {
                 if ( 'Media' === $result['info'] ) {
                         $results[$key]['permalink'] =
 wp_get_attachment_url( $result['ID'] );
                 }
         }
         return $results;
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/22180#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list