Skip to content

Commit e5043f8

Browse files
authored
Update force-https.php
1 parent a369ddf commit e5043f8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

force-https.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,25 @@ function force_https_securize_url( $value ) {
9898
add_filter( 'wp_get_attachment_url', 'force_https_securize_url', 999 );
9999
add_filter( 'wp_redirect', 'force_https_securize_url', 999 );
100100

101+
// enforce https on filtered HTML output
102+
function force_https_filter_output( $content ) {
103+
104+
// return original if not a string
105+
if ( ! is_string( $content ) || strpos( $content, 'http://' ) === false ) {
106+
return $content;
107+
}
108+
109+
// replace http with https
110+
return str_replace( 'http://', 'https://', $content );
111+
}
112+
113+
// apply to simple HTML filters that need URL enforcement
114+
add_filter( 'post_thumbnail_html', 'force_https_filter_output', 999 );
115+
add_filter( 'render_block', 'force_https_filter_output', 999 );
116+
add_filter( 'rest_pre_echo_response', 'force_https_filter_output', 999 );
117+
add_filter( 'walker_nav_menu_start_el', 'force_https_filter_output', 999 );
118+
add_filter( 'woocommerce_email_footer_text', 'force_https_filter_output', 999 );
119+
101120
// force https on all elements and attributes with urls
102121
add_filter( 'the_content', 'force_https_process_content', 20 );
103122
function force_https_process_content( $content ) {

0 commit comments

Comments
 (0)