| 1 |
<?php |
| 2 |
namespace Elementor; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; // Exit if accessed directly. |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Elementor skins manager. |
| 10 |
* |
| 11 |
* Elementor skins manager handler class is responsible for registering and |
| 12 |
* initializing all the supported skins. |
| 13 |
* |
| 14 |
* @since 1.0.0 |
| 15 |
*/ |
| 16 |
class Skins_Manager { |
| 17 |
|
| 18 |
/** |
| 19 |
* Registered Skins. |
| 20 |
* |
| 21 |
* Holds the list of all the registered skins for all the widgets. |
| 22 |
* |
| 23 |
* @since 1.0.0 |
| 24 |
* @access private |
| 25 |
* |
| 26 |
* @var array Registered skins. |
| 27 |
*/ |
| 28 |
private $_skins = []; |
| 29 |
|
| 30 |
/** |
| 31 |
* Add new skin. |
| 32 |
* |
| 33 |
* Register a single new skin for a widget. |
| 34 |
* |
| 35 |
* @since 1.0.0 |
| 36 |
* @access public |
| 37 |
* |
| 38 |
* @param Widget_Base $widget Elementor widget. |
| 39 |
* @param Skin_Base $skin Elementor skin. |
| 40 |
* |
| 41 |
* @return true True if skin added. |
| 42 |
*/ |
| 43 |
public function add_skin( Widget_Base $widget, Skin_Base $skin ) { |
| 44 |
$widget_name = $widget->get_name(); |
| 45 |
|
| 46 |
if ( ! isset( $this->_skins[ $widget_name ] ) ) { |
| 47 |
$this->_skins[ $widget_name ] = []; |
| 48 |
} |
| 49 |
|
| 50 |
$this->_skins[ $widget_name ][ $skin->get_id() ] = $skin; |
| 51 |
|
| 52 |
return true; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Remove a skin. |
| 57 |
* |
| 58 |
* Unregister an existing skin from a widget. |
| 59 |
* |
| 60 |
* @since 1.0.0 |
| 61 |
* @access public |
| 62 |
* |
| 63 |
* @param Widget_Base $widget Elementor widget. |
| 64 |
* @param string $skin_id Elementor skin ID. |
| 65 |
* |
| 66 |
* @return true|\WP_Error True if skin removed, `WP_Error` otherwise. |
| 67 |
*/ |
| 68 |
public function remove_skin( Widget_Base $widget, $skin_id ) { |
| 69 |
$widget_name = $widget->get_name(); |
| 70 |
|
| 71 |
if ( ! isset( $this->_skins[ $widget_name ][ $skin_id ] ) ) { |
| 72 |
return new \WP_Error( 'Cannot remove not-exists skin.' ); |
| 73 |
} |
| 74 |
|
| 75 |
unset( $this->_skins[ $widget_name ][ $skin_id ] ); |
| 76 |
|
| 77 |
return true; |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Get skins. |
| 82 |
* |
| 83 |
* Retrieve all the skins assigned for a specific widget. |
| 84 |
* |
| 85 |
* @since 1.0.0 |
| 86 |
* @access public |
| 87 |
* |
| 88 |
* @param Widget_Base $widget Elementor widget. |
| 89 |
* |
| 90 |
* @return false|array Skins if the widget has skins, False otherwise. |
| 91 |
*/ |
| 92 |
public function get_skins( Widget_Base $widget ) { |
| 93 |
$widget_name = $widget->get_name(); |
| 94 |
|
| 95 |
if ( ! isset( $this->_skins[ $widget_name ] ) ) { |
| 96 |
return false; |
| 97 |
} |
| 98 |
|
| 99 |
return $this->_skins[ $widget_name ]; |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Skins manager constructor. |
| 104 |
* |
| 105 |
* Initializing Elementor skins manager by requiring the skin base class. |
| 106 |
* |
| 107 |
* @since 1.0.0 |
| 108 |
* @access public |
| 109 |
*/ |
| 110 |
public function __construct() { |
| 111 |
require ELEMENTOR_PATH . 'includes/base/skin-base.php'; |
| 112 |
} |
| 113 |
} |
| 114 |
|