Problem is with class FixCSS. The code there is wrong. It doesn’t consider if there are multiple selectors for the same section between curly braces. So when there is something like this:
.selector1, .selector2, .selector3 {color:#000;margin:0 5px}
it fails because it only adds the new custom selector to the first one, in this case .selector1. This should be fixed.
This is the fixed function:
public function add_selector( $css, $custom_selector ) {
$css = $this->minify( $css );
// Split the CSS string into an array of individual rules.
$css_rules = preg_split('/}/', $css);
// Initialize the new CSS string.
$new_css = '';
// Loop through each rule.
foreach ( $css_rules as $rule ) {
// Split the rule into the selector and properties.
$parts = preg_split('/{/', $rule, 2);
// If the rule has a selector and properties.
if ( count($parts) == 2 ) {
// Check if $parts[0] has multiple selectors
if (strpos($parts[0], ",") !== false) {
$selectors = preg_split('/,/', $parts[0]);
$count = count($selectors);
foreach ( $selectors as $selector ) {
// Add the selector to the new CSS string.
$new_css .= $custom_selector . ' ' . trim($selector);
// Add comma only if it's not the last one
if (--$count > 0) $new_css .= ", ";
}
// Add newline and curly brace at end
$new_css .= " {\n";
} else {
// Add the selector to the new CSS string, followed by a newline.
$new_css .= $custom_selector . ' ' . trim($parts[0]) . " {\n";
}
// Add the properties to the new CSS string, indented by one tab.
$new_css .= "\t" . trim($parts[1]) . "\n";
// Add the closing curly brace for the rule.
$new_css .= "}\n";
}
}
$new_css = $this->minify( $new_css );
return $new_css;
}
-
This reply was modified 2 years, 6 months ago by
fidoboy.
Hi,
Sorry for the inconvenience. We would like to inform you that “Custom CSS” is a premium feature of our plugin. According to the forum guidelines, support for commercial products is not permitted in the forums. To get support for the premium version of our plugin, kindly contact us through our official support channel.
Thanks for sharing functions! Have a nice day!
Hi there,
A big thanks for letting us know about this bug. We appreciate your input and the time you took to give us a solution.
Our team is cooking a completely revamped version of the plugin. It will bring plenty of enhancements and fixes many issues.
Stay tuned! A big thanks for sticking with us.