class-entity.php
1 year ago
class-extras.php
1 year ago
class-repository-helpers.php
1 day ago
class-wrapper.php
1 week ago
index.php
2 years ago
class-extras.php
66 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Extras functionality needed to be on the root level. |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * @since 1.48.2 |
| 8 | */ |
| 9 | |
| 10 | namespace AdvancedAds\Traits; |
| 11 | |
| 12 | use Advanced_Ads; |
| 13 | use AdvancedAds\Constants; |
| 14 | use AdvancedAds\Utilities\Sanitize; |
| 15 | |
| 16 | defined( 'ABSPATH' ) || exit; |
| 17 | |
| 18 | /** |
| 19 | * Trait Extras. |
| 20 | */ |
| 21 | trait Extras { |
| 22 | /** |
| 23 | * Frontend prefix for classes and IDs. |
| 24 | * |
| 25 | * @var string |
| 26 | */ |
| 27 | private $frontend_prefix = null; |
| 28 | |
| 29 | /** |
| 30 | * Get frontend prefix for classes and IDs. |
| 31 | * |
| 32 | * @return string |
| 33 | */ |
| 34 | public function get_frontend_prefix(): string { |
| 35 | // Early bail!! |
| 36 | if ( null !== $this->frontend_prefix ) { |
| 37 | return $this->frontend_prefix; |
| 38 | } |
| 39 | |
| 40 | $options = Advanced_Ads::get_instance()->options(); |
| 41 | |
| 42 | if ( ! isset( $options['front-prefix'] ) ) { |
| 43 | if ( isset( $options['id-prefix'] ) ) { |
| 44 | // deprecated: keeps widgets working that previously received an id based on the front-prefix. |
| 45 | $frontend_prefix = $options['id-prefix']; |
| 46 | } else { |
| 47 | $frontend_prefix = preg_match( '/[A-Za-z][A-Za-z0-9_]{4}/', wp_parse_url( get_home_url(), PHP_URL_HOST ), $result ) |
| 48 | ? $result[0] . '-' |
| 49 | : Constants::DEFAULT_FRONTEND_PREFIX; |
| 50 | } |
| 51 | } else { |
| 52 | $frontend_prefix = $options['front-prefix']; |
| 53 | } |
| 54 | /** |
| 55 | * Applying the filter here makes sure that it is the same frontend prefix for all |
| 56 | * calls on this page impression |
| 57 | * |
| 58 | * @param string $frontend_prefix |
| 59 | */ |
| 60 | $this->frontend_prefix = (string) apply_filters( 'advanced-ads-frontend-prefix', $frontend_prefix ); |
| 61 | $this->frontend_prefix = Sanitize::frontend_prefix( $frontend_prefix ); |
| 62 | |
| 63 | return $this->frontend_prefix; |
| 64 | } |
| 65 | } |
| 66 |