Make WordPress Core

Ticket #29727: 29727.diff

File 29727.diff, 1.4 KB (added by thomaswm, 9 years ago)

Replace local HTTP URLs in post content using a filter

  • wp-includes/default-filters.php

     
    151151add_filter( 'comment_text', 'convert_smilies',    20 );
    152152add_filter( 'comment_text', 'wpautop',            30 );
    153153
     154if ( is_ssl() ) {
     155        add_filter( 'the_content', 'wp_post_content_ssl_urls' );
     156        add_filter( 'the_excerpt', 'wp_post_content_ssl_urls' );
     157        add_filter( 'comment_text', 'wp_post_content_ssl_urls' );
     158}
     159
     160
    154161add_filter( 'comment_excerpt', 'convert_chars' );
    155162
    156163add_filter( 'list_cats',         'wptexturize' );
  • wp-includes/functions.php

     
    39423942}
    39433943
    39443944/**
     3945 * Rewrites local HTTP URLs in post content to HTTPS URLs
     3946 *
     3947 * @since 4.5.0
     3948 *
     3949 * @param string $content Post content.
     3950 * @return string Post content with rewritten URLs
     3951 */
     3952function wp_post_content_ssl_urls( $content ) {
     3953        $search = array(
     3954                home_url( '', 'http' ),
     3955                site_url( '', 'http' )
     3956        );
     3957        $replace = array(
     3958                home_url( '', 'https' ),
     3959                site_url( '', 'https' )
     3960        );
     3961        return str_replace( $search, $replace, $content );
     3962}
     3963
     3964/**
    39453965 * Guess the URL for the site.
    39463966 *
    39473967 * Will remove wp-admin links to retrieve only return URLs not in the wp-admin