| 1 |
<?php |
| 2 |
namespace MasterAddons\Inc\Admin\PopupBuilder; |
| 3 |
|
| 4 |
if (!defined('ABSPATH')) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
class Popup_Templates { |
| 9 |
|
| 10 |
private $templates = []; |
| 11 |
|
| 12 |
public function __construct() { |
| 13 |
$this->init_templates(); |
| 14 |
} |
| 15 |
|
| 16 |
private function init_templates() { |
| 17 |
$this->templates = [ |
| 18 |
'newsletter' => [ |
| 19 |
'name' => __('Newsletter Signup', 'master-addons'), |
| 20 |
'description' => __('Collect email addresses with a clean newsletter form', 'master-addons'), |
| 21 |
'type' => 'modal', |
| 22 |
'category' => 'lead-generation', |
| 23 |
'content' => '<div class="ma-popup-template-newsletter"> |
| 24 |
<h2>Join Our Newsletter</h2> |
| 25 |
<p>Get the latest updates and exclusive offers delivered to your inbox.</p> |
| 26 |
<form class="ma-newsletter-form"> |
| 27 |
<input type="email" placeholder="Enter your email address" required> |
| 28 |
<button type="submit">Subscribe</button> |
| 29 |
</form> |
| 30 |
<p class="ma-privacy-text">We respect your privacy. Unsubscribe at any time.</p> |
| 31 |
</div>', |
| 32 |
'settings' => [ |
| 33 |
'trigger_scroll_percent' => 50, |
| 34 |
'popup_width' => '500px', |
| 35 |
'popup_animation' => 'fade' |
| 36 |
] |
| 37 |
], |
| 38 |
'discount' => [ |
| 39 |
'name' => __('Discount Offer', 'master-addons'), |
| 40 |
'description' => __('Promote special offers and discounts', 'master-addons'), |
| 41 |
'type' => 'modal', |
| 42 |
'category' => 'sales', |
| 43 |
'content' => '<div class="ma-popup-template-discount"> |
| 44 |
<div class="ma-discount-badge">SPECIAL OFFER</div> |
| 45 |
<h2>Get 25% OFF</h2> |
| 46 |
<p>Limited time offer! Use code <strong>SAVE25</strong> at checkout.</p> |
| 47 |
<button class="ma-cta-button">Shop Now</button> |
| 48 |
<p class="ma-expires">Offer expires in 48 hours</p> |
| 49 |
</div>', |
| 50 |
'settings' => [ |
| 51 |
'popup_width' => '450px', |
| 52 |
'popup_animation' => 'zoom' |
| 53 |
] |
| 54 |
], |
| 55 |
'cookie-consent' => [ |
| 56 |
'name' => __('Cookie Consent', 'master-addons'), |
| 57 |
'description' => __('GDPR compliant cookie consent notice', 'master-addons'), |
| 58 |
'type' => 'notification', |
| 59 |
'category' => 'compliance', |
| 60 |
'content' => '<div class="ma-popup-template-cookie"> |
| 61 |
<p>We use cookies to enhance your experience. By continuing to visit this site you agree to our use of cookies. |
| 62 |
<a href="/privacy-policy">Learn more</a></p> |
| 63 |
<button class="ma-accept-cookies">Accept</button> |
| 64 |
<button class="ma-decline-cookies">Decline</button> |
| 65 |
</div>', |
| 66 |
'settings' => [ |
| 67 |
'popup_position' => 'bottom-center', |
| 68 |
'popup_width' => '100%', |
| 69 |
'show_overlay' => false, |
| 70 |
'close_on_overlay' => false |
| 71 |
] |
| 72 |
], |
| 73 |
'contact' => [ |
| 74 |
'name' => __('Contact Form', 'master-addons'), |
| 75 |
'description' => __('Quick contact form for visitor inquiries', 'master-addons'), |
| 76 |
'type' => 'slide-in', |
| 77 |
'category' => 'lead-generation', |
| 78 |
'content' => '<div class="ma-popup-template-contact"> |
| 79 |
<h3>Get in Touch</h3> |
| 80 |
<form class="ma-contact-form"> |
| 81 |
<input type="text" placeholder="Your Name" required> |
| 82 |
<input type="email" placeholder="Your Email" required> |
| 83 |
<textarea placeholder="Your Message" rows="4" required></textarea> |
| 84 |
<button type="submit">Send Message</button> |
| 85 |
</form> |
| 86 |
</div>', |
| 87 |
'settings' => [ |
| 88 |
'trigger_scroll_percent' => 75, |
| 89 |
'popup_position' => 'bottom-right', |
| 90 |
'popup_width' => '350px', |
| 91 |
'popup_animation' => 'slide-left' |
| 92 |
] |
| 93 |
], |
| 94 |
'announcement' => [ |
| 95 |
'name' => __('Announcement Bar', 'master-addons'), |
| 96 |
'description' => __('Important announcements and notices', 'master-addons'), |
| 97 |
'type' => 'notification', |
| 98 |
'category' => 'informational', |
| 99 |
'content' => '<div class="ma-popup-template-announcement"> |
| 100 |
<p><strong>Important:</strong> Our store will be closed for maintenance on Sunday. |
| 101 |
<a href="#">Learn more →</a></p> |
| 102 |
</div>', |
| 103 |
'settings' => [ |
| 104 |
'popup_position' => 'top-center', |
| 105 |
'popup_width' => '100%', |
| 106 |
'show_overlay' => false, |
| 107 |
'popup_animation' => 'slide-down' |
| 108 |
] |
| 109 |
], |
| 110 |
'exit-intent' => [ |
| 111 |
'name' => __('Exit Intent', 'master-addons'), |
| 112 |
'description' => __('Capture leaving visitors with special offer', 'master-addons'), |
| 113 |
'type' => 'modal', |
| 114 |
'category' => 'lead-generation', |
| 115 |
'content' => '<div class="ma-popup-template-exit"> |
| 116 |
<h2>Wait! Don\'t Leave Yet</h2> |
| 117 |
<p>Get an exclusive 15% discount before you go!</p> |
| 118 |
<form class="ma-exit-form"> |
| 119 |
<input type="email" placeholder="Enter your email for the discount" required> |
| 120 |
<button type="submit">Get My Discount</button> |
| 121 |
</form> |
| 122 |
<p class="ma-no-thanks"><a href="#">No thanks, I\'ll pay full price</a></p> |
| 123 |
</div>', |
| 124 |
'settings' => [ |
| 125 |
'popup_width' => '500px', |
| 126 |
'popup_animation' => 'zoom', |
| 127 |
'show_frequency' => 'once_session' |
| 128 |
] |
| 129 |
], |
| 130 |
'video' => [ |
| 131 |
'name' => __('Video Popup', 'master-addons'), |
| 132 |
'description' => __('Showcase videos in a popup', 'master-addons'), |
| 133 |
'type' => 'modal', |
| 134 |
'category' => 'media', |
| 135 |
'content' => '<div class="ma-popup-template-video"> |
| 136 |
<div class="ma-video-wrapper"> |
| 137 |
<iframe width="560" height="315" |
| 138 |
src="https://www.youtube.com/embed/dQw4w9WgXcQ" |
| 139 |
frameborder="0" |
| 140 |
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" |
| 141 |
allowfullscreen> |
| 142 |
</iframe> |
| 143 |
</div> |
| 144 |
</div>', |
| 145 |
'settings' => [ |
| 146 |
'popup_width' => '800px', |
| 147 |
'popup_animation' => 'fade' |
| 148 |
] |
| 149 |
], |
| 150 |
'age-verification' => [ |
| 151 |
'name' => __('Age Verification', 'master-addons'), |
| 152 |
'description' => __('Verify visitor age before accessing content', 'master-addons'), |
| 153 |
'type' => 'full-screen', |
| 154 |
'category' => 'compliance', |
| 155 |
'content' => '<div class="ma-popup-template-age"> |
| 156 |
<h2>Age Verification Required</h2> |
| 157 |
<p>You must be 18 years or older to enter this site.</p> |
| 158 |
<div class="ma-age-buttons"> |
| 159 |
<button class="ma-age-confirm">I am 18 or older</button> |
| 160 |
<button class="ma-age-deny">I am under 18</button> |
| 161 |
</div> |
| 162 |
</div>', |
| 163 |
'settings' => [ |
| 164 |
'show_close_button' => false, |
| 165 |
'close_on_overlay' => false, |
| 166 |
'close_on_esc' => false, |
| 167 |
'show_frequency' => 'once' |
| 168 |
] |
| 169 |
], |
| 170 |
'social-follow' => [ |
| 171 |
'name' => __('Social Media Follow', 'master-addons'), |
| 172 |
'description' => __('Encourage social media follows', 'master-addons'), |
| 173 |
'type' => 'corner', |
| 174 |
'category' => 'social', |
| 175 |
'content' => '<div class="ma-popup-template-social"> |
| 176 |
<h4>Follow Us</h4> |
| 177 |
<div class="ma-social-icons"> |
| 178 |
<a href="#" class="ma-social-facebook">Facebook</a> |
| 179 |
<a href="#" class="ma-social-twitter">Twitter</a> |
| 180 |
<a href="#" class="ma-social-instagram">Instagram</a> |
| 181 |
<a href="#" class="ma-social-youtube">YouTube</a> |
| 182 |
</div> |
| 183 |
</div>', |
| 184 |
'settings' => [ |
| 185 |
'trigger_scroll_percent' => 80, |
| 186 |
'popup_position' => 'bottom-left', |
| 187 |
'popup_width' => '250px', |
| 188 |
'popup_animation' => 'slide-up' |
| 189 |
] |
| 190 |
], |
| 191 |
'survey' => [ |
| 192 |
'name' => __('Quick Survey', 'master-addons'), |
| 193 |
'description' => __('Collect feedback with a quick survey', 'master-addons'), |
| 194 |
'type' => 'modal', |
| 195 |
'category' => 'feedback', |
| 196 |
'content' => '<div class="ma-popup-template-survey"> |
| 197 |
<h3>Quick Survey</h3> |
| 198 |
<p>Help us improve! How would you rate your experience?</p> |
| 199 |
<div class="ma-survey-options"> |
| 200 |
<label><input type="radio" name="rating" value="excellent"> Excellent</label> |
| 201 |
<label><input type="radio" name="rating" value="good"> Good</label> |
| 202 |
<label><input type="radio" name="rating" value="fair"> Fair</label> |
| 203 |
<label><input type="radio" name="rating" value="poor"> Poor</label> |
| 204 |
</div> |
| 205 |
<textarea placeholder="Additional comments (optional)" rows="3"></textarea> |
| 206 |
<button type="submit">Submit Feedback</button> |
| 207 |
</div>', |
| 208 |
'settings' => [ |
| 209 |
'popup_width' => '400px', |
| 210 |
'popup_animation' => 'fade' |
| 211 |
] |
| 212 |
] |
| 213 |
]; |
| 214 |
} |
| 215 |
|
| 216 |
public function render() { |
| 217 |
$categories = $this->get_categories(); |
| 218 |
?> |
| 219 |
<div class="wrap ma-popup-templates"> |
| 220 |
<h1><?php esc_html_e('Popup Templates', 'master-addons'); ?></h1> |
| 221 |
<p><?php esc_html_e('Choose from our pre-designed templates to get started quickly.', 'master-addons'); ?></p> |
| 222 |
|
| 223 |
<div class="ma-template-categories"> |
| 224 |
<button class="ma-category-filter active" data-category="all"> |
| 225 |
<?php esc_html_e('All Templates', 'master-addons'); ?> |
| 226 |
</button> |
| 227 |
<?php foreach ($categories as $key => $label) : ?> |
| 228 |
<button class="ma-category-filter" data-category="<?php echo esc_attr($key); ?>"> |
| 229 |
<?php echo esc_html($label); ?> |
| 230 |
</button> |
| 231 |
<?php endforeach; ?> |
| 232 |
</div> |
| 233 |
|
| 234 |
<div class="ma-templates-grid"> |
| 235 |
<?php foreach ($this->templates as $key => $template) : ?> |
| 236 |
<div class="ma-template-card" data-category="<?php echo esc_attr($template['category']); ?>"> |
| 237 |
<div class="ma-template-preview"> |
| 238 |
<div class="ma-template-content"> |
| 239 |
<?php echo wp_kses_post( $template['content'] ); ?> |
| 240 |
</div> |
| 241 |
</div> |
| 242 |
<div class="ma-template-info"> |
| 243 |
<h3><?php echo esc_html($template['name']); ?></h3> |
| 244 |
<p><?php echo esc_html($template['description']); ?></p> |
| 245 |
<div class="ma-template-meta"> |
| 246 |
<span class="ma-template-type"><?php echo esc_html($this->get_type_label($template['type'])); ?></span> |
| 247 |
<span class="ma-template-category"><?php echo esc_html($categories[$template['category']]); ?></span> |
| 248 |
</div> |
| 249 |
<button class="button button-primary ma-use-template" |
| 250 |
data-template="<?php echo esc_attr($key); ?>"> |
| 251 |
<?php esc_html_e('Use This Template', 'master-addons'); ?> |
| 252 |
</button> |
| 253 |
</div> |
| 254 |
</div> |
| 255 |
<?php endforeach; ?> |
| 256 |
</div> |
| 257 |
</div> |
| 258 |
<?php |
| 259 |
} |
| 260 |
|
| 261 |
private function get_categories() { |
| 262 |
return [ |
| 263 |
'lead-generation' => __('Lead Generation', 'master-addons'), |
| 264 |
'sales' => __('Sales & Promotions', 'master-addons'), |
| 265 |
'compliance' => __('Compliance', 'master-addons'), |
| 266 |
'informational' => __('Informational', 'master-addons'), |
| 267 |
'social' => __('Social Media', 'master-addons'), |
| 268 |
'media' => __('Media', 'master-addons'), |
| 269 |
'feedback' => __('Feedback', 'master-addons'), |
| 270 |
]; |
| 271 |
} |
| 272 |
|
| 273 |
private function get_type_label($type) { |
| 274 |
$types = [ |
| 275 |
'notification' => __('Notification Bar', 'master-addons'), |
| 276 |
'modal' => __('Modal', 'master-addons'), |
| 277 |
'slide-in' => __('Slide-in', 'master-addons'), |
| 278 |
'full-screen' => __('Full Screen', 'master-addons'), |
| 279 |
'corner' => __('Corner Popup', 'master-addons'), |
| 280 |
]; |
| 281 |
|
| 282 |
return isset($types[$type]) ? $types[$type] : $type; |
| 283 |
} |
| 284 |
|
| 285 |
public function get_template($key) { |
| 286 |
return isset($this->templates[$key]) ? $this->templates[$key] : null; |
| 287 |
} |
| 288 |
} |