-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix (WooCommerce): remove css styles displayed on shop page #3381
base: develop
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,29 @@ | |
exit; | ||
} | ||
|
||
/** | ||
* In WooCommerce Shop page, <style> tags are stripped out and the CSS styles are displayed in the frontend. | ||
* This function removes the <style> tags and CSS styles before they are stripped out. | ||
*/ | ||
if ( ! function_exists( 'stackable_pre_kses_woocomerce_shop' ) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move this code from here to the new |
||
|
||
function stackable_pre_kses_woocomerce_shop( $content, $allowed_html, $context ) { | ||
// Check if we are on the WooCommerce Shop page | ||
if ( function_exists('is_shop' ) && is_shop() ) { | ||
$optimized_css = get_post_meta( wc_get_page_id( 'shop' ), 'stackable_optimized_css', true ); | ||
|
||
// remove CSS before kses strips out <style> tags | ||
if ( ! empty( $optimized_css ) ) { | ||
$content = str_replace( '<style>' . $optimized_css . '</style>', '', $content ); | ||
} | ||
|
||
} | ||
return $content; | ||
} | ||
|
||
add_filter('pre_kses', 'stackable_pre_kses_woocomerce_shop', 10, 3); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See whether you can check for the existence of the |
||
} | ||
|
||
if ( ! function_exists( 'stackable_allow_wp_kses_allowed_html' ) ) { | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition is becoming long and hard to read, can we split this to make it more readable? I feel uneasy that we're mingling WooCommerce code inside our normal behavior, let's add a filter so that we can split woocommerce compatibility into it's own file - we can add a
src/compatibility/woocommerce.php
and place the necessary compatibility code there.