| 1 |
<?php |
| 2 |
|
| 3 |
namespace MasterAddons\Inc\Admin\WidgetBuilder; |
| 4 |
|
| 5 |
use MasterAddons\Inc\Classes\Helper; |
| 6 |
|
| 7 |
defined('ABSPATH') || exit; |
| 8 |
|
| 9 |
/** |
| 10 |
* Brand-colours the PRO badge on the Master Addons Widgets panel category. |
| 11 |
* |
| 12 |
* The badge itself is rendered by Elementor from the category's `promotion` |
| 13 |
* property (registered in class-master-elementor-addons.php). This class only |
| 14 |
* restyles it, scoped to our own category so Elementor's own Pro promotions |
| 15 |
* keep their native colour. |
| 16 |
*/ |
| 17 |
class Widget_Category_Badge |
| 18 |
{ |
| 19 |
const CATEGORY_SLUG = 'master-addons-widgets'; |
| 20 |
|
| 21 |
/** Brand purple. Reads well on the light editor theme. */ |
| 22 |
const BRAND_COLOR = '#6814cd'; |
| 23 |
|
| 24 |
/** |
| 25 |
* Lighter tint for the dark editor theme — #6814cd only reaches roughly |
| 26 |
* 2:1 contrast against Elementor's near-black panel (#1f2124). |
| 27 |
*/ |
| 28 |
const BRAND_COLOR_DARK = '#a855f7'; |
| 29 |
|
| 30 |
private static $_instance = null; |
| 31 |
|
| 32 |
public function __construct() |
| 33 |
{ |
| 34 |
add_action('elementor/editor/after_enqueue_styles', [$this, 'enqueue_badge_style']); |
| 35 |
} |
| 36 |
|
| 37 |
public function enqueue_badge_style() |
| 38 |
{ |
| 39 |
// Licensed sites get no promotion registered, so nothing to style. |
| 40 |
if (Helper::jltma_premium()) { |
| 41 |
return; |
| 42 |
} |
| 43 |
|
| 44 |
// The plain `color` declaration is the fallback for browsers without |
| 45 |
// light-dark(); Elementor sets color-scheme on the root, so supporting |
| 46 |
// browsers pick the tint matching the editor's UI theme. |
| 47 |
$css = sprintf( |
| 48 |
'#elementor-panel-category-%1$s .elementor-panel-heading-promotion a,' . |
| 49 |
'#elementor-panel-category-%1$s .elementor-panel-heading-promotion i' . |
| 50 |
'{color:%2$s;color:light-dark(%2$s,%3$s)}' . |
| 51 |
'#elementor-panel-category-%1$s .elementor-panel-heading-promotion a:hover{opacity:.8}', |
| 52 |
self::CATEGORY_SLUG, |
| 53 |
self::BRAND_COLOR, |
| 54 |
self::BRAND_COLOR_DARK |
| 55 |
); |
| 56 |
|
| 57 |
wp_register_style('jltma-widget-category-badge', false, [], JLTMA_VER); |
| 58 |
wp_enqueue_style('jltma-widget-category-badge'); |
| 59 |
wp_add_inline_style('jltma-widget-category-badge', $css); |
| 60 |
} |
| 61 |
|
| 62 |
public static function get_instance() |
| 63 |
{ |
| 64 |
if (is_null(self::$_instance)) { |
| 65 |
self::$_instance = new self(); |
| 66 |
} |
| 67 |
return self::$_instance; |
| 68 |
} |
| 69 |
} |
| 70 |
|