@@ -65,7 +65,7 @@ function force_https_securize_url( $value ) {
6565 return set_url_scheme ( $ value , 'https ' );
6666}
6767
68- // apply https to urls used across wordpress and woocommerce
68+ // apply https to urls used across wordpress
6969add_filter ( 'admin_url ' , 'force_https_securize_url ' , 10 );
7070add_filter ( 'author_feed_link ' , 'force_https_securize_url ' , 10 );
7171add_filter ( 'category_feed_link ' , 'force_https_securize_url ' , 10 );
@@ -87,11 +87,20 @@ function force_https_securize_url( $value ) {
8787add_filter ( 'rest_url ' , 'force_https_securize_url ' , 10 );
8888add_filter ( 'tag_link ' , 'force_https_securize_url ' , 10 );
8989add_filter ( 'term_link ' , 'force_https_securize_url ' , 10 );
90- add_filter ( 'wc_get_endpoint_url ' , 'force_https_securize_url ' , 10 );
91- add_filter ( 'woocommerce_account_endpoint_url ' , 'force_https_securize_url ' , 10 );
9290add_filter ( 'wp_get_attachment_url ' , 'force_https_securize_url ' , 10 );
9391add_filter ( 'wp_logout_url ' , 'force_https_securize_url ' , 10 );
9492
93+ // apply https to woocommerce urls if woocommerce is active
94+ if ( class_exists ( 'WooCommerce ' ) ) {
95+ add_filter ( 'wc_get_endpoint_url ' , 'force_https_securize_url ' , 10 );
96+ add_filter ( 'woocommerce_account_endpoint_url ' , 'force_https_securize_url ' , 10 );
97+ add_filter ( 'woocommerce_email_footer_text ' , 'force_https_filter_output ' , 999 );
98+ add_filter ( 'woocommerce_rest_prepare_coupon ' , 'force_https_filter_output ' , 999 );
99+ add_filter ( 'woocommerce_rest_prepare_customer ' , 'force_https_filter_output ' , 999 );
100+ add_filter ( 'woocommerce_rest_prepare_order ' , 'force_https_filter_output ' , 999 );
101+ add_filter ( 'woocommerce_rest_prepare_product ' , 'force_https_filter_output ' , 999 );
102+ }
103+
95104// enforce https on html content that may contain urls
96105function force_https_filter_output ( $ content ) {
97106 // return unchanged if not a string or does not contain http
@@ -103,19 +112,14 @@ function force_https_filter_output( $content ) {
103112 return str_replace ( 'http:// ' , 'https:// ' , $ content );
104113}
105114
106- // apply https enforcement to html content in various wordpress areas
115+ // apply https enforcement to html content
107116add_filter ( 'comment_text ' , 'force_https_filter_output ' , 20 );
108117add_filter ( 'post_thumbnail_html ' , 'force_https_filter_output ' , 10 );
109118add_filter ( 'render_block ' , 'force_https_filter_output ' , 20 );
110119add_filter ( 'rest_pre_echo_response ' , 'force_https_filter_output ' , 999 );
111120add_filter ( 'walker_nav_menu_start_el ' , 'force_https_filter_output ' , 10 );
112121add_filter ( 'widget_text ' , 'force_https_filter_output ' , 20 );
113122add_filter ( 'widget_text_content ' , 'force_https_filter_output ' , 20 );
114- add_filter ( 'woocommerce_email_footer_text ' , 'force_https_filter_output ' , 999 );
115- add_filter ( 'woocommerce_rest_prepare_coupon ' , 'force_https_filter_output ' , 999 );
116- add_filter ( 'woocommerce_rest_prepare_customer ' , 'force_https_filter_output ' , 999 );
117- add_filter ( 'woocommerce_rest_prepare_order ' , 'force_https_filter_output ' , 999 );
118- add_filter ( 'woocommerce_rest_prepare_product ' , 'force_https_filter_output ' , 999 );
119123add_filter ( 'wp_redirect ' , 'force_https_filter_output ' , 999 );
120124add_filter ( 'wp_safe_redirect ' , 'force_https_filter_output ' , 999 );
121125
0 commit comments