astra_parse_selector( string $selectors, string|array $keywords = '' )
Parses selectors and conditionally removes plugin-specific selectors.
Description
Usage:
$selectors = '.class1, .class2, .class3'; $filtered = astra_parse_selector( $selectors, 'wc' );
Parameters
- $selectors
-
(string) (Required) Full selector string (comma-separated).
- $keywords
-
(string|array) (Optional) Keywords to filter out selectors. If a string is provided, it will be converted to an array.
Default value: ''
Return
(string) Final selector string.
Source
File: classes/astra-common-functions.php
function astra_parse_selector( $selectors, $keywords = '' ) {
$selector_array = explode( ',', $selectors );
$filtered_selectors = array();
// If $keywords is a string, convert it to an array.
if ( is_string( $keywords ) ) {
$keywords = array( $keywords );
}
foreach ( $selector_array as $selector ) {
$selector = trim( $selector );
$ignore_selector = false;
foreach ( $keywords as $keyword ) {
switch ( $keyword ) {
case 'wc':
case 'woocommerce':
if ( ! defined( 'WC_VERSION' ) && strpos( $selector, 'woocommerce' ) !== false ) {
$ignore_selector = true;
break 2;
}
break;
case 'el':
case 'elementor':
if ( ! defined( 'ELEMENTOR_VERSION' ) && strpos( $selector, 'elementor' ) !== false ) {
$ignore_selector = true;
break 2;
}
break;
// Add more cases here for other plugins.
}
}
if ( ! $ignore_selector ) {
$filtered_selectors[] = $selector;
}
}
return implode( ', ', $filtered_selectors );
}
Expand full source code Collapse full source code View on Trac
Changelog
| Version | Description |
|---|---|
| 4.11.5 | Introduced. |