class-helper.php
4 years ago
class-loader.php
4 years ago
class-panel-options.php
4 years ago
widgets-passing-lists.php
4 years ago
widgets-passing-lists.php
127 lines
| 1 | <?php |
| 2 | namespace EcafeAddons; |
| 3 | |
| 4 | if (!defined('ABSPATH')) { |
| 5 | exit; |
| 6 | } // Exit if accessed directly |
| 7 | |
| 8 | if ( ! class_exists( 'ecafeWidgetsPassed' ) ) { |
| 9 | |
| 10 | /** |
| 11 | * Ecafe widgets passed |
| 12 | */ |
| 13 | class ecafeWidgetsPassed { |
| 14 | |
| 15 | private static $instance = null; |
| 16 | |
| 17 | /** |
| 18 | * Constructor |
| 19 | */ |
| 20 | private function __construct() { |
| 21 | $this->init(); |
| 22 | } |
| 23 | |
| 24 | public function init() { |
| 25 | add_action( 'elementor/widgets/widgets_registered', array($this, 'addWidgets' ) ); |
| 26 | add_action( 'elementor/controls/controls_registered', array( $this, 'add_controls' ), 10 ); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Add Controls Extensions |
| 31 | */ |
| 32 | public function add_controls( $controls_manager ) { |
| 33 | $grouped_control = array( |
| 34 | 'ecafe-widgets-extras' => 'Ecafe_Widgets_Extras', |
| 35 | ); |
| 36 | foreach ( $grouped_control as $control_id => $class_name ) { |
| 37 | if ( $this->extensionWidgets( $control_id, true ) ) { |
| 38 | new $class_name(); |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Add widgets |
| 45 | */ |
| 46 | public function addWidgets( $widgetsexEcutive ) { |
| 47 | |
| 48 | $combined = array( |
| 49 | 'ecafe-accordion' => '\EcafeAddons\Widgets\Ecafe_Accordion', |
| 50 | 'ecafe-adv-text-block' => '\EcafeAddons\Widgets\Ecafe_Adv_Text_Block', |
| 51 | 'ecafe-business-hours' => '\EcafeAddons\Widgets\Ecafe_Business_Hours', |
| 52 | 'ecafe-button' => '\EcafeAddons\Widgets\Ecafe_Button', |
| 53 | 'ecafe-changelog' => '\EcafeAddons\Widgets\Ecafe_Changelog', |
| 54 | 'ecafe-darkmode-styling' => '\EcafeAddons\Widgets\Ecafe_Darkmode_Styling', |
| 55 | 'ecafe-chart' => '\EcafeAddons\Widgets\Ecafe_Chart', |
| 56 | 'ecafe-image-hover-effect' => '\EcafeAddons\Widgets\Ecafe_Image_Hover_Effect', |
| 57 | 'ecafe-infobox' => '\EcafeAddons\Widgets\Ecafe_Infobox', |
| 58 | 'ecafe-social-icons' => '\EcafeAddons\Widgets\Ecafe_Social_Icons', |
| 59 | 'ecafe-title' => '\EcafeAddons\Widgets\Ecafe_Title', |
| 60 | 'ecafe-grid-post-listing' => '\EcafeAddons\Widgets\Ecafe_Grid_Post_Listing', |
| 61 | 'ecafe-lottie' => '\EcafeAddons\Widgets\Ecafe_Lottie', |
| 62 | 'ecafe-marketing-link' => '\EcafeAddons\Widgets\Ecafe_Marketing_Link', |
| 63 | 'ecafe-tabs' => '\EcafeAddons\Widgets\Ecafe_Tabs', |
| 64 | ); |
| 65 | |
| 66 | $optionFetch=\EcafeHelper::ecafeGetOption('general','widgetsload'); |
| 67 | if(!empty($optionFetch)){ |
| 68 | array_push($optionFetch, "ecafe-widgets"); |
| 69 | foreach ( $combined as $widgetId => $className ) { |
| 70 | if(in_array($widgetId,$optionFetch)){ |
| 71 | if ( $this->carryWidgets( $widgetId, true ) ) { |
| 72 | $widgetsexEcutive->register_widget_type( new $className() ); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Carry widgets |
| 81 | */ |
| 82 | public function carryWidgets( $widgetId, $combined = false ) { |
| 83 | |
| 84 | $filename = sprintf('element/widgets/'.$widgetId.'.php'); |
| 85 | |
| 86 | if ( ! file_exists( ECAFE_PATH.$filename ) ) { |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | require ECAFE_PATH.$filename; |
| 91 | |
| 92 | return true; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Extension Includes |
| 97 | */ |
| 98 | public function extensionWidgets( $widgetId, $combined = false ) { |
| 99 | |
| 100 | $filename = sprintf('element/extension/'.$widgetId.'.php'); |
| 101 | |
| 102 | if ( ! file_exists( ECAFE_PATH.$filename ) ) { |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | require ECAFE_PATH.$filename; |
| 107 | |
| 108 | return true; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Instance fetch |
| 113 | */ |
| 114 | public static function instanceFetch( $handlers = array() ) { |
| 115 | |
| 116 | if ( null == self::$instance ) { |
| 117 | self::$instance = new self( $handlers ); |
| 118 | } |
| 119 | return self::$instance; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | } |
| 124 | |
| 125 | function ecafeWidgetsPassed() { |
| 126 | return ecafeWidgetsPassed::instanceFetch(); |
| 127 | } |