@@ -65,7 +65,7 @@ function force_https_securize_url( $value ) {
65
65
return set_url_scheme ( $ value , 'https ' );
66
66
}
67
67
68
- // apply https to urls used across wordpress and woocommerce
68
+ // apply https to urls used across wordpress
69
69
add_filter ( 'admin_url ' , 'force_https_securize_url ' , 10 );
70
70
add_filter ( 'author_feed_link ' , 'force_https_securize_url ' , 10 );
71
71
add_filter ( 'category_feed_link ' , 'force_https_securize_url ' , 10 );
@@ -87,11 +87,20 @@ function force_https_securize_url( $value ) {
87
87
add_filter ( 'rest_url ' , 'force_https_securize_url ' , 10 );
88
88
add_filter ( 'tag_link ' , 'force_https_securize_url ' , 10 );
89
89
add_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 );
92
90
add_filter ( 'wp_get_attachment_url ' , 'force_https_securize_url ' , 10 );
93
91
add_filter ( 'wp_logout_url ' , 'force_https_securize_url ' , 10 );
94
92
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
+
95
104
// enforce https on html content that may contain urls
96
105
function force_https_filter_output ( $ content ) {
97
106
// return unchanged if not a string or does not contain http
@@ -103,19 +112,14 @@ function force_https_filter_output( $content ) {
103
112
return str_replace ( 'http:// ' , 'https:// ' , $ content );
104
113
}
105
114
106
- // apply https enforcement to html content in various wordpress areas
115
+ // apply https enforcement to html content
107
116
add_filter ( 'comment_text ' , 'force_https_filter_output ' , 20 );
108
117
add_filter ( 'post_thumbnail_html ' , 'force_https_filter_output ' , 10 );
109
118
add_filter ( 'render_block ' , 'force_https_filter_output ' , 20 );
110
119
add_filter ( 'rest_pre_echo_response ' , 'force_https_filter_output ' , 999 );
111
120
add_filter ( 'walker_nav_menu_start_el ' , 'force_https_filter_output ' , 10 );
112
121
add_filter ( 'widget_text ' , 'force_https_filter_output ' , 20 );
113
122
add_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 );
119
123
add_filter ( 'wp_redirect ' , 'force_https_filter_output ' , 999 );
120
124
add_filter ( 'wp_safe_redirect ' , 'force_https_filter_output ' , 999 );
121
125
0 commit comments