1+ <?php
2+ /**
3+ * Subscribe notice layout.
4+ *
5+ * @package Feedzy
6+ * @since 5.1.0
7+ */
8+
9+ ?>
10+ <div class="feedzy-container">
11+ <div class="feedzy-helper-notice" style="padding: 30px; position: relative">
12+ <button
13+ type="button"
14+ class="feedzy-notice-dismiss"
15+ aria-label="<?php esc_attr_e ( 'Dismiss this notice ' , 'feedzy-rss-feeds ' ); ?> "
16+ >
17+ ×
18+ </button>
19+
20+ <h2 class="feedzy-notice-title">
21+ <?php esc_html_e ( 'Welcome to Feedzy! ' , 'feedzy-rss-feeds ' ); ?>
22+ </h2>
23+
24+ <p class="feedzy-notice-subtitle">
25+ <?php
26+ $ users_number = number_format_i18n ( 50000 );
27+ echo esc_html (
28+ sprintf (
29+ // translators: %s is the number of users.
30+ __ ( 'Join %s+ users aggregating RSS feeds effortlessly ' , 'feedzy-rss-feeds ' ),
31+ $ users_number
32+ )
33+ );
34+ ?>
35+ </p>
36+
37+ <form id="feedzy-subscribe-form" method="post" action="">
38+ <?php wp_nonce_field ( 'feedzy_subscribe_nonce ' , 'feedzy_subscribe_nonce_field ' ); ?>
39+
40+ <input
41+ type="email"
42+ id="fz_subscribe_email"
43+ name="feedzy_email"
44+ value="<?php echo esc_attr ( get_option ( 'admin_email ' ) ); ?> "
45+ class="feedzy-helper-subscribe"
46+ required
47+ >
48+
49+ <div class="mb-20">
50+ <div class="feedzy-helper-info">
51+ <?php esc_html_e ( 'Get tips, updates & unlock exclusive guides ' , 'feedzy-rss-feeds ' ); ?>
52+ </div>
53+ <div style="font-size: 16px;">
54+ <?php esc_html_e ( 'Help improve Feedzy with anonymous usage insights ' , 'feedzy-rss-feeds ' ); ?>
55+ </div>
56+ </div>
57+
58+ <button
59+ type="button"
60+ name="feedzy_subscribe_button"
61+ class="feedzy-subscribe"
62+ >
63+ <?php esc_html_e ( 'Get Started ' , 'feedzy-rss-feeds ' ); ?> →
64+ </button>
65+ </form>
66+
67+ <div class="feedzy-notice-error"></div>
68+ </div>
69+ </div>
70+ <style>
71+ .feedzy-notice-dismiss {
72+ position: absolute;
73+ top: 10px;
74+ right: 10px;
75+ background: transparent;
76+ border: none;
77+ cursor: pointer;
78+ font-size: 24px;
79+ }
80+
81+ .feedzy-notice-title {
82+ font-size: clamp(28px, 5vw, 42px);
83+ margin: 0 0 10px 0;
84+ }
85+
86+ .feedzy-helper-notice .feedzy-notice-subtitle {
87+ font-size: 20px;
88+ margin-bottom: 20px;
89+ }
90+
91+ .feedzy-wrap .feedzy-helper-subscribe {
92+ width: 100%;
93+ max-width: 600px;
94+ padding: 15px;
95+ font-size: 16px;
96+ border: none;
97+ border-radius: 5px;
98+ margin-bottom: 20px;
99+ }
100+
101+ .feedzy-helper-info {
102+ font-size: 18px;
103+ font-weight: 600;
104+ margin-bottom: 8px;
105+ }
106+
107+ .feedzy-helper-notice .feedzy-subscribe{
108+ background: white;
109+ padding: 12px 30px;
110+ font-size: 18px;
111+ font-weight: 600;
112+ border: none;
113+ border-radius: 5px;
114+ cursor: pointer;
115+ }
116+
117+ .feedzy-notice-error {
118+ display: none;
119+ color: #d63638;
120+ margin-top: 10px;
121+ padding: 8px;
122+ background-color: #fcf0f1;
123+ border: 1px solid #d63638;
124+ border-radius: 4px;
125+ }
126+ </style>
127+ <script>
128+ document.addEventListener('DOMContentLoaded', () => {
129+ const showError = (message) => {
130+ const errorDiv = document.querySelector('.feedzy-notice-error');
131+ errorDiv.textContent = message;
132+ errorDiv.style.display = 'block';
133+ };
134+
135+ const hideError = () => {
136+ const errorDiv = document.querySelector('.feedzy-notice-error');
137+ errorDiv.style.display = 'none';
138+ errorDiv.textContent = '';
139+ };
140+
141+ const send = async (formData) => {
142+ return await fetch(window.ajaxurl, {
143+ method: 'POST',
144+ body: formData,
145+ credentials: 'same-origin'
146+ });
147+ }
148+
149+ const dismissNotice = async (button) => {
150+ const notice = button.closest('.feedzy-helper-notice');
151+ try {
152+ button.disabled = true;
153+ const nonceField = document.getElementById('feedzy_subscribe_nonce_field');
154+
155+ const formData = new FormData();
156+ formData.append('action', 'feedzy_dashboard_subscribe');
157+ formData.append('_wpnonce', nonceField.value);
158+ formData.append('skip', 'yes');
159+
160+ await send(formData);
161+ } catch (error) {
162+ console.error('Error dismissing notice:', error);
163+ } finally {
164+ button.disabled = false;
165+ jQuery(notice).fadeOut(400, function() {
166+ jQuery(this).remove();
167+ });
168+ }
169+ };
170+
171+ const handleSubscription = async (button) => {
172+ try {
173+ hideError();
174+ const subscriptionForm = document.getElementById('feedzy-subscribe-form');
175+
176+ if ( !subscriptionForm.checkValidity() ) {
177+ subscriptionForm.reportValidity();
178+ return;
179+ }
180+
181+ const emailElement = document.getElementById('fz_subscribe_email');
182+ const nonceField = document.getElementById('feedzy_subscribe_nonce_field');
183+
184+ button.disabled = true;
185+
186+ const formData = new FormData();
187+ formData.append('action', 'feedzy_dashboard_subscribe');
188+ formData.append('_wpnonce', nonceField.value);
189+ formData.append('with_subscribe', '1');
190+ formData.append('email', emailElement.value);
191+
192+ const response = await send(formData);
193+ const result = await response.json();
194+
195+ if (result.success) {
196+ const notice = document.querySelector('.feedzy-helper-notice');
197+ jQuery(notice).fadeOut(400, function() {
198+ jQuery(this).remove();
199+ });
200+
201+ if (result.data?.redirect_to) {
202+ window.location.href = result.data.redirect_to;
203+ }
204+ } else {
205+ const errorMessage = result.data?.message || 'Unknown';
206+ showError(errorMessage);
207+ }
208+ } catch (error) {
209+ showError(error);
210+ } finally {
211+ button.disabled = false;
212+ }
213+ };
214+
215+ const dismissButton = document.querySelector('.feedzy-notice-dismiss');
216+ const subscribeButton = document.querySelector('.feedzy-subscribe');
217+
218+ if (dismissButton) {
219+ dismissButton.addEventListener('click', (event) => {
220+ event.preventDefault();
221+ dismissNotice(event.target);
222+ });
223+ }
224+
225+ if (subscribeButton) {
226+ subscribeButton.addEventListener('click', (event) => {
227+ event.preventDefault();
228+ handleSubscription(event.target);
229+ });
230+ }
231+ });
232+ </script>
0 commit comments