| 1 |
<?php |
| 2 |
/** |
| 3 |
* Widget Registry |
| 4 |
* |
| 5 |
* Single source of truth for every MarqueeAll widget. |
| 6 |
* Elementor registration, Widget Manager admin page, and future |
| 7 |
* additions all read from this one list. |
| 8 |
* |
| 9 |
* @package MarqueeAll |
| 10 |
* @since 1.3.0 |
| 11 |
*/ |
| 12 |
|
| 13 |
namespace MASSCIE; |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Class Widget_Registry |
| 21 |
*/ |
| 22 |
final class Widget_Registry { |
| 23 |
|
| 24 |
/** |
| 25 |
* Singleton instance. |
| 26 |
* |
| 27 |
* @var Widget_Registry|null |
| 28 |
*/ |
| 29 |
private static $instance = null; |
| 30 |
|
| 31 |
/** |
| 32 |
* All registered widget definitions. |
| 33 |
* |
| 34 |
* @var array |
| 35 |
*/ |
| 36 |
private $widgets = []; |
| 37 |
|
| 38 |
/** |
| 39 |
* Get singleton instance. |
| 40 |
* |
| 41 |
* @return Widget_Registry |
| 42 |
*/ |
| 43 |
public static function instance() { |
| 44 |
if ( null === self::$instance ) { |
| 45 |
self::$instance = new self(); |
| 46 |
} |
| 47 |
return self::$instance; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Private constructor — populates the widget list. |
| 52 |
*/ |
| 53 |
private function __construct() { |
| 54 |
$this->build(); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Build the widget list. |
| 59 |
* |
| 60 |
* Schema per entry: |
| 61 |
* slug — kebab-case option key shown in Widget Manager |
| 62 |
* title — human-readable label |
| 63 |
* class — fully-qualified PHP class (single backslash at runtime) |
| 64 |
* file — path relative to MASSCIE_PATH (no leading slash) |
| 65 |
* icon — Elementor eicon class for the admin card |
| 66 |
* docs — documentation URL |
| 67 |
* demo — live demo URL |
| 68 |
* pro — true = Pro-only, toggle disabled in Widget Manager |
| 69 |
* |
| 70 |
* @return void |
| 71 |
*/ |
| 72 |
private function build() { |
| 73 |
$docs = 'https://marqueeall.com/docs/'; |
| 74 |
$demo = 'https://marqueeall.com/demo/'; |
| 75 |
|
| 76 |
$this->widgets = [ |
| 77 |
[ |
| 78 |
'slug' => 'text-marquee', |
| 79 |
'title' => __( 'Text Marquee', 'marqueeall' ), |
| 80 |
'class' => 'MASSCIE\Widgets\Text_Marquee', |
| 81 |
'file' => 'includes/widgets/class-text-marquee.php', |
| 82 |
'icon' => 'eicon-animated-headline', |
| 83 |
'docs' => $docs . 'text-marquee/', |
| 84 |
'demo' => $demo . 'text-marquee/', |
| 85 |
'pro' => false, |
| 86 |
], |
| 87 |
[ |
| 88 |
'slug' => 'image-marquee', |
| 89 |
'title' => __( 'Image Marquee', 'marqueeall' ), |
| 90 |
'class' => 'MASSCIE\Widgets\Image_Marquee', |
| 91 |
'file' => 'includes/widgets/class-image-marquee.php', |
| 92 |
'icon' => 'eicon-slider-push', |
| 93 |
'docs' => $docs . 'image-marquee/', |
| 94 |
'demo' => $demo . 'image-marquee/', |
| 95 |
'pro' => false, |
| 96 |
], |
| 97 |
[ |
| 98 |
'slug' => 'testimonial-marquee', |
| 99 |
'title' => __( 'Testimonial Marquee', 'marqueeall' ), |
| 100 |
'class' => 'MASSCIE\Widgets\Testimonial_Marquee', |
| 101 |
'file' => 'includes/widgets/class-testimonial-marquee.php', |
| 102 |
'icon' => 'eicon-testimonial', |
| 103 |
'docs' => $docs . 'testimonial-marquee/', |
| 104 |
'demo' => $demo . 'testimonial-marquee/', |
| 105 |
'pro' => false, |
| 106 |
], |
| 107 |
[ |
| 108 |
'slug' => 'news-ticker', |
| 109 |
'title' => __( 'News Ticker', 'marqueeall' ), |
| 110 |
'class' => 'MASSCIE\Widgets\News_Ticker', |
| 111 |
'file' => 'includes/widgets/class-news-ticker.php', |
| 112 |
'icon' => 'eicon-post-list', |
| 113 |
'docs' => $docs . 'news-ticker/', |
| 114 |
'demo' => $demo . 'news-ticker/', |
| 115 |
'pro' => false, |
| 116 |
], |
| 117 |
[ |
| 118 |
'slug' => 'post-grid-marquee', |
| 119 |
'title' => __( 'Post Grid Marquee', 'marqueeall' ), |
| 120 |
'class' => 'MASSCIE\Widgets\Post_Grid_Marquee', |
| 121 |
'file' => 'includes/widgets/class-post-grid-marquee.php', |
| 122 |
'icon' => 'eicon-posts-grid', |
| 123 |
'docs' => $docs . 'post-grid-marquee/', |
| 124 |
'demo' => $demo . 'post-grid-marquee/', |
| 125 |
'pro' => false, |
| 126 |
], |
| 127 |
[ |
| 128 |
'slug' => 'team-members-marquee', |
| 129 |
'title' => __( 'Team Members Marquee', 'marqueeall' ), |
| 130 |
'class' => 'MASSCIE\Widgets\Team_Members_Marquee', |
| 131 |
'file' => 'includes/widgets/class-team-members-marquee.php', |
| 132 |
'icon' => 'eicon-person', |
| 133 |
'docs' => $docs . 'team-members-marquee/', |
| 134 |
'demo' => $demo . 'team-members-marquee/', |
| 135 |
'pro' => false, |
| 136 |
], |
| 137 |
[ |
| 138 |
'slug' => 'text-scramble', |
| 139 |
'title' => __( 'Text Scramble', 'marqueeall' ), |
| 140 |
'class' => 'MASSCIE\Widgets\Text_Scramble', |
| 141 |
'file' => 'includes/widgets/class-text-scramble.php', |
| 142 |
'icon' => 'eicon-t-letter', |
| 143 |
'docs' => $docs . 'text-scramble/', |
| 144 |
'demo' => $demo . 'text-scramble/', |
| 145 |
'pro' => false, |
| 146 |
], |
| 147 |
[ |
| 148 |
'slug' => 'crypto-marquee', |
| 149 |
'title' => __( 'Crypto Marquee', 'marqueeall' ), |
| 150 |
'class' => 'MASSCIE\Widgets\Crypto_Marquee', |
| 151 |
'file' => 'includes/widgets/class-crypto-marquee.php', |
| 152 |
'icon' => 'eicon-price-list', |
| 153 |
'docs' => $docs . 'crypto-marquee/', |
| 154 |
'demo' => $demo . 'crypto-marquee/', |
| 155 |
'pro' => false, |
| 156 |
], |
| 157 |
[ |
| 158 |
'slug' => 'faq-marquee', |
| 159 |
'title' => __( 'FAQ Marquee', 'marqueeall' ), |
| 160 |
'class' => 'MASSCIE\Widgets\Faq_Marquee', |
| 161 |
'file' => 'includes/widgets/class-faq-marquee.php', |
| 162 |
'icon' => 'eicon-accordion', |
| 163 |
'docs' => $docs . 'faq-marquee/', |
| 164 |
'demo' => $demo . 'faq-marquee/', |
| 165 |
'pro' => false, |
| 166 |
], |
| 167 |
]; |
| 168 |
|
| 169 |
/** |
| 170 |
* Filters the widget registry. |
| 171 |
* |
| 172 |
* Pro add-ons and third-party code can append widget definitions here. |
| 173 |
* |
| 174 |
* @since 1.3.0 |
| 175 |
* |
| 176 |
* @param array $widgets Array of widget definition arrays. |
| 177 |
*/ |
| 178 |
$this->widgets = apply_filters( 'marqueeall_widget_registry', $this->widgets ); |
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* Return all widget definitions. |
| 183 |
* |
| 184 |
* @return array |
| 185 |
*/ |
| 186 |
public function get_all() { |
| 187 |
return $this->widgets; |
| 188 |
} |
| 189 |
|
| 190 |
/** |
| 191 |
* Return a single widget definition by slug. |
| 192 |
* |
| 193 |
* @param string $slug Widget slug. |
| 194 |
* @return array|null |
| 195 |
*/ |
| 196 |
public function get( $slug ) { |
| 197 |
foreach ( $this->widgets as $widget ) { |
| 198 |
if ( $widget['slug'] === $slug ) { |
| 199 |
return $widget; |
| 200 |
} |
| 201 |
} |
| 202 |
return null; |
| 203 |
} |
| 204 |
|
| 205 |
/** |
| 206 |
* Return all registered slugs. |
| 207 |
* |
| 208 |
* @return string[] |
| 209 |
*/ |
| 210 |
public function get_slugs() { |
| 211 |
return array_column( $this->widgets, 'slug' ); |
| 212 |
} |
| 213 |
|
| 214 |
/** |
| 215 |
* Return total widget count. |
| 216 |
* |
| 217 |
* @return int |
| 218 |
*/ |
| 219 |
public function count() { |
| 220 |
return count( $this->widgets ); |
| 221 |
} |
| 222 |
} |
| 223 |
|