[wp-trac] [WordPress Trac] #15928: wp_get_attachment_url does not check for HTTPS

WordPress Trac noreply at wordpress.org
Wed Jun 18 13:44:12 UTC 2014


#15928: wp_get_attachment_url does not check for HTTPS
-------------------------------------+-----------------------
 Reporter:  atetlaw                  |       Owner:
     Type:  defect (bug)             |      Status:  assigned
 Priority:  normal                   |   Milestone:  4.0
Component:  Permalinks               |     Version:  3.0.3
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:
-------------------------------------+-----------------------

Comment (by chaoix):

 Here is my solution to this issue. Running it on several installs with no
 problems.
 {{{
 #!php
 //Fix SSL on Post Thumbnail URLs
         function ssl_post_thumbnail_urls($url, $post_id) {
                 //Skip file attachments
                 if( !wp_attachment_is_image($post_id) )
                         return $url;

                 //Correct protocol for https connections
                 list($protocol, $uri) = explode('://', $url, 2);
                 if( is_ssl() ) {
                         if( 'http' == $protocol )
                                 $protocol = 'https';
                 } else {
                         if( 'https' == $protocol )
                                 $protocol = 'http';
                 }

                 return $protocol.'://'.$uri;
         }
         add_filter('wp_get_attachment_url', 'ssl_post_thumbnail_urls', 10,
 2);
 }}}

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


More information about the wp-trac mailing list