PluginProbe
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites / trunk
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites vtrunk
4.1.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.1.2 2.5.0 2.5.3 2.6.1 All 38 releases
blockspare / admin / notice-theme.php

notice-theme.php in BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites trunk, at admin/notice-theme.php

375 lines 12.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly.
3 defined( 'ABSPATH' ) || exit;
4
5 class Blockspare_NewSpare_Notice extends Blockspare_Setup {
6
7 /**
8 * Constructor.
9 */
10 public function __construct() {
11
12 $dismiss_url = wp_nonce_url(
13 add_query_arg(
14 'blockspare_setup_notice_dismiss',
15 'newspare',
16 admin_url()
17 ),
18 'blockspare_setup_notice_dismiss_nonce',
19 '_blockspare_setup_notice_dismiss_nonce'
20 );
21
22 $temporary_dismiss_url = wp_nonce_url(
23 add_query_arg(
24 'blockspare_setup_notice_dismiss_temporary',
25 'newspare',
26 admin_url()
27 ),
28 'blockspare_setup_notice_dismiss_temporary_nonce',
29 '_blockspare_setup_notice_dismiss_temporary_nonce'
30 );
31
32 parent::__construct(
33 'newspare',
34 'info',
35 $dismiss_url,
36 $temporary_dismiss_url
37 );
38
39 // Process dismiss actions before checking conditions
40 $this->process_dismiss_actions();
41
42 $this->set_notice_time();
43 $this->set_dismiss_notice();
44 }
45
46 /**
47 * Set initial notice time.
48 */
49 private function set_notice_time() {
50 if ( ! get_option( 'blockspare_newspare_notice_start_time' ) ) {
51 update_option( 'blockspare_newspare_notice_start_time', time() );
52 }
53 }
54
55 /**
56 * Listen and process the dismiss actions when a user clicks them.
57 */
58 private function process_dismiss_actions() {
59 if ( ! function_exists( 'get_current_user_id' ) ) {
60 return;
61 }
62
63 $user_id = get_current_user_id();
64 if ( ! $user_id ) {
65 return;
66 }
67
68 // Handle Permanent Dismiss
69 if ( isset( $_GET['blockspare_setup_notice_dismiss'] ) && 'newspare' === $_GET['blockspare_setup_notice_dismiss'] ) {
70 if ( isset( $_GET['_blockspare_setup_notice_dismiss_nonce'] ) && wp_verify_nonce( $_GET['_blockspare_setup_notice_dismiss_nonce'], 'blockspare_setup_notice_dismiss_nonce' ) ) {
71 update_user_meta( $user_id, 'blockspare_newspare_notice_dismiss', 'yes' );
72 wp_safe_redirect( remove_query_arg( array( 'blockspare_setup_notice_dismiss', '_blockspare_setup_notice_dismiss_nonce' ) ) );
73 exit;
74 }
75 }
76
77 // Handle Temporary Dismiss
78 if ( isset( $_GET['blockspare_setup_notice_dismiss_temporary'] ) && 'newspare' === $_GET['blockspare_setup_notice_dismiss_temporary'] ) {
79 if ( isset( $_GET['_blockspare_setup_notice_dismiss_temporary_nonce'] ) && wp_verify_nonce( $_GET['_blockspare_setup_notice_dismiss_temporary_nonce'], 'blockspare_setup_notice_dismiss_temporary_nonce' ) ) {
80 update_user_meta( $user_id, 'blockspare_newspare_notice_dismiss_temporary_start_time', time() );
81 wp_safe_redirect( remove_query_arg( array( 'blockspare_setup_notice_dismiss_temporary', '_blockspare_setup_notice_dismiss_temporary_nonce' ) ) );
82 exit;
83 }
84 }
85 }
86
87 /**
88 * Set dismiss conditions.
89 */
90 public function set_dismiss_notice() {
91 $user_id = get_current_user_id();
92
93 $is_permanently_dismissed = ( 'yes' === get_user_meta( $user_id, 'blockspare_newspare_notice_dismiss', true ) );
94
95 $temporary_dismiss_time = (int) get_user_meta( $user_id, 'blockspare_newspare_notice_dismiss_temporary_start_time', true );
96 $is_temporarily_dismissed = ( $temporary_dismiss_time > strtotime( '-7 days' ) );
97
98 // If permanently or temporarily dismissed, hide the notice
99 if ( $is_permanently_dismissed || $is_temporarily_dismissed ) {
100 add_filter( 'blockspare_newspare_notice_dismiss', '__return_true' );
101 } else {
102 add_filter( 'blockspare_newspare_notice_dismiss', '__return_false' );
103 }
104 }
105
106 /**
107 * Get NewSpare action button.
108 */
109 private function get_newspare_action() {
110
111 $theme = wp_get_theme( 'newspare' );
112
113 // Already active.
114 if ( 'newspare' === get_stylesheet() ) {
115
116 return array(
117 'url' => admin_url( 'site-editor.php' ),
118 'text' => __( 'Open Site Editor', 'blockspare' ),
119 );
120 }
121
122 // Installed but inactive.
123 if ( $theme->exists() ) {
124
125 return array(
126 'url' => wp_nonce_url(
127 admin_url( 'themes.php?action=activate&stylesheet=newspare' ),
128 'switch-theme_newspare'
129 ),
130 'text' => __( 'Activate NewSpare', 'blockspare' ),
131 );
132 }
133
134 // Not installed.
135 return array(
136 'url' => wp_nonce_url(
137 self_admin_url( 'update.php?action=install-theme&theme=newspare' ),
138 'install-theme_newspare'
139 ),
140 'text' => __( 'Install & Activate NewSpare', 'blockspare' ),
141 );
142 }
143
144 /**
145 * Notice markup.
146 */
147 public function notice_markup() {
148
149 $action = $this->get_newspare_action();
150
151 ?>
152
153 <div
154 class="notice notice-info blockspare-notice-newspare"
155 style="
156 padding:24px;
157 position:relative;
158 border-left:4px solid #2271b1;
159 background:#fff;
160 "
161 >
162
163 <div
164 style="
165 display:flex;
166 justify-content:space-between;
167 gap:30px;
168 align-items:flex-start;
169 flex-wrap:wrap;
170 "
171 >
172
173 <div style="flex:1; min-width:300px;">
174
175 <div
176 style="
177 display:inline-block;
178 background:#e8f2ff;
179 color:#2271b1;
180 padding:4px 10px;
181 border-radius:30px;
182 font-size:12px;
183 font-weight:600;
184 margin-bottom:14px;
185 "
186 >
187 <?php esc_html_e( 'Recommended Block Theme', 'blockspare' ); ?>
188 </div>
189
190 <h2
191 style="
192 margin:0 0 12px;
193 font-size:24px;
194 line-height:1.4;
195 font-weight:700;
196 "
197 >
198 <?php esc_html_e( 'Build Faster with NewSpare 🚀', 'blockspare' ); ?>
199 </h2>
200
201 <p
202 style="
203 margin:0 0 16px;
204 font-size:14px;
205 color:#555;
206 max-width:900px;
207 line-height:1.8;
208 "
209 >
210 <?php esc_html_e( 'NewSpare is a modern Full Site Editing WordPress theme built for news, magazine, blogs, and business websites. It works seamlessly with BlockSpare blocks, patterns, and starter templates — helping you launch professional websites visually with Gutenberg.', 'blockspare' ); ?>
211 </p>
212
213 <div
214 style="
215 display:flex;
216 flex-wrap:wrap;
217 gap:8px;
218 margin-bottom:18px;
219 "
220 >
221
222 <span style="background:#f6f7f7; padding:7px 12px; border-radius:5px; font-size:12px;">
223 Full Site Editing
224 </span>
225
226 <span style="background:#f6f7f7; padding:7px 12px; border-radius:5px; font-size:12px;">
227 📰 News & Magazine Ready
228 </span>
229
230 <span style="background:#f6f7f7; padding:7px 12px; border-radius:5px; font-size:12px;">
231 🌙 Light & Dark Mode
232 </span>
233
234 <span style="background:#f6f7f7; padding:7px 12px; border-radius:5px; font-size:12px;">
235 🛒 WooCommerce Support
236 </span>
237
238 <span style="background:#f6f7f7; padding:7px 12px; border-radius:5px; font-size:12px;">
239 Gutenberg Optimized
240 </span>
241
242 <span style="background:#f6f7f7; padding:7px 12px; border-radius:5px; font-size:12px;">
243 📱 Responsive Design
244 </span>
245
246 </div>
247
248 <div
249 style="
250 display:flex;
251 flex-wrap:wrap;
252 gap:10px;
253 align-items:center;
254 "
255 >
256
257 <a
258 class="button button-primary"
259 href="<?php echo esc_url( $action['url'] ); ?>"
260 >
261 <?php echo esc_html( $action['text'] ); ?>
262 </a>
263
264 <a
265 class="button"
266 target="_blank"
267 href="<?php echo esc_url( 'https://afthemes.com/products/newspare/' ); ?>"
268 >
269 <?php esc_html_e( 'Theme Details', 'blockspare' ); ?>
270 </a>
271
272 <a
273 class="button button-secondary"
274 target="_blank"
275 href="<?php echo esc_url( 'https://wordpress.org/themes/newspare/' ); ?>"
276 >
277 <?php esc_html_e( 'Live Preview', 'blockspare' ); ?>
278 </a>
279
280 </div>
281
282 </div>
283
284 <div
285 style="
286 width:220px;
287 background:#f8fbff;
288 border:1px solid #dcdcde;
289 border-radius:10px;
290 padding:18px;
291 "
292 >
293
294 <div
295 style="
296 font-size:13px;
297 font-weight:600;
298 color:#2271b1;
299 margin-bottom:12px;
300 "
301 >
302 <?php esc_html_e( 'Why NewSpare?', 'blockspare' ); ?>
303 </div>
304
305 <ul
306 style="
307 margin:0;
308 padding-left:18px;
309 color:#555;
310 line-height:1.8;
311 font-size:13px;
312 "
313 >
314 <li><?php esc_html_e( 'Designed for Gutenberg', 'blockspare' ); ?></li>
315 <li><?php esc_html_e( 'Works perfectly with BlockSpare', 'blockspare' ); ?></li>
316 <li><?php esc_html_e( 'Professional starter templates included', 'blockspare' ); ?></li>
317 <li><?php esc_html_e( 'Optimized for speed & SEO', 'blockspare' ); ?></li>
318 </ul>
319
320 </div>
321
322 </div>
323
324 <a
325 class="notice-dismiss"
326 href="<?php echo esc_url( $this->dismiss_url ); ?>"
327 ></a>
328
329 </div>
330
331 <?php
332 }
333 }
334
335 /**
336 * Initialize notice.
337 */
338 function blockspare_newspare_notice_init() {
339
340 if ( ! is_admin() ) {
341 return;
342 }
343
344 new Blockspare_NewSpare_Notice();
345 }
346
347 add_action(
348 'admin_init',
349 'blockspare_newspare_notice_init'
350 );
351
352 /**
353 * Redirect to Site Editor after activating NewSpare.
354 */
355 function blockspare_newspare_redirect_to_editor() {
356
357 if ( 'newspare' !== get_stylesheet() ) {
358 return;
359 }
360
361 if ( ! isset( $_GET['activate'] ) ) {
362 return;
363 }
364
365 wp_safe_redirect(
366 admin_url( 'site-editor.php' )
367 );
368
369 exit;
370 }
371
372 add_action(
373 'after_switch_theme',
374 'blockspare_newspare_redirect_to_editor'
375 );