@@ -126,17 +126,17 @@ function force_https_filter_output( $content ) {
126126add_filter ( 'widget_text ' , 'force_https_filter_output ' , 20 );
127127add_filter ( 'widget_text_content ' , 'force_https_filter_output ' , 20 );
128128
129- // enforce https on elements and inline content
129+ // enforce https on elements and inline content
130130add_filter ( 'the_content ' , 'force_https_process_content ' , 20 );
131131
132132function force_https_process_content ( $ content ) {
133- // match elements with src, href, action, content, cite, or background attributes
133+ // match elements with src, href, action, content, or formaction attributes
134134 static $ element_pattern = '#(?i)(<(?:a|img|iframe|video|audio|source|form|link|embed|object|track|script|meta|input|button)\b[^>]*\s*(?:href|src|action|content|formaction)=[" \'])http://([^" \']+)# ' ;
135135
136- // match script and style content
136+ // match script and style content
137137 static $ script_style_pattern = '#(<(?i:script|style)\b[^>]*>)(.*?)</(?i:script|style)>#s ' ;
138138
139- // replace http with https in elements
139+ // replace http with https in elements
140140 $ content = preg_replace_callback (
141141 $ element_pattern ,
142142 function ( $ matches ) {
@@ -145,15 +145,16 @@ function ( $matches ) {
145145 $ content
146146 );
147147
148- // replace http and escaped http in script and style blocks
148+ // replace http and escaped http in script and style blocks
149149 return preg_replace_callback (
150150 $ script_style_pattern ,
151151 function ( $ matches ) {
152+ preg_match ('/<\s*(script|style)/i ' , $ matches [1 ], $ tag_match );
152153 return $ matches [1 ] . str_replace (
153- ['http:// ' , 'http: \\ / \ \/ ' ],
154- ['https:// ' , 'https: \\ / \ \/ ' ],
154+ ['http:// ' , 'http:\/ \/ ' ],
155+ ['https:// ' , 'https:\/ \/ ' ],
155156 $ matches [2 ]
156- ) . '</ ' . ( $ matches [1 ][ 1 ] === ' s ' ? ' script ' : ' style ' ) . '> ' ;
157+ ) . '</ ' . $ tag_match [1 ] . '> ' ;
157158 },
158159 $ content
159160 );
0 commit comments