PluginProbe
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites / 4.1.0
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites v4.1.0
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-setup.php

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

335 lines 10.5 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_Setup {
6
7 public $name;
8 public $type;
9 public $dismiss_url;
10 public $temporary_dismiss_url;
11 public $pricing_url;
12 public $current_user_id;
13
14 /**
15 * Constructor.
16 */
17 public function __construct( $name, $type, $dismiss_url, $temporary_dismiss_url ) {
18
19 $this->name = $name;
20 $this->type = $type;
21 $this->dismiss_url = $dismiss_url;
22 $this->temporary_dismiss_url = $temporary_dismiss_url;
23 $this->pricing_url = 'https://www.blockspare.com/';
24 $this->current_user_id = get_current_user_id();
25
26 add_action( 'admin_notices', array( $this, 'notice' ) );
27
28 $this->dismiss_notice();
29 $this->dismiss_notice_temporary();
30 }
31
32 /**
33 * Display notice.
34 */
35 public function notice() {
36
37 if ( ! current_user_can( 'publish_posts' ) ) {
38 return;
39 }
40
41 $current_screen = get_current_screen();
42
43 if ( ! $current_screen ) {
44 return;
45 }
46
47 if (
48 'dashboard' !== $current_screen->id &&
49 'themes' !== $current_screen->id &&
50 'plugins' !== $current_screen->id
51 ) {
52 return;
53 }
54
55 if ( ! $this->is_dismiss_notice() ) {
56 $this->notice_markup();
57 }
58 }
59
60 /**
61 * Check if notice dismissed.
62 */
63 private function is_dismiss_notice() {
64 return apply_filters( 'blockspare_' . $this->name . '_notice_dismiss', false );
65 }
66
67 /**
68 * Notice markup.
69 */
70 public function notice_markup() {
71 echo '';
72 }
73
74 /**
75 * Permanently dismiss notice.
76 */
77 public function dismiss_notice() {
78
79 if (
80 isset( $_GET['blockspare_setup_notice_dismiss'] ) &&
81 isset( $_GET['_blockspare_setup_notice_dismiss_nonce'] )
82 ) {
83
84 if (
85 ! wp_verify_nonce(
86 wp_unslash( $_GET['_blockspare_setup_notice_dismiss_nonce'] ),
87 'blockspare_setup_notice_dismiss_nonce'
88 )
89 ) {
90 wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'blockspare' ) );
91 }
92
93 if ( ! current_user_can( 'publish_posts' ) ) {
94 wp_die( esc_html__( 'Cheatin&#8217; huh?', 'blockspare' ) );
95 }
96
97 $dismiss_notice = sanitize_text_field( wp_unslash( $_GET['blockspare_setup_notice_dismiss'] ) );
98
99 // FIX: Match current notice name dynamically instead of hardcoded 'setup'
100 if ( $this->name === $dismiss_notice ) {
101 update_user_meta(
102 $this->current_user_id,
103 'blockspare_' . $dismiss_notice . '_notice_dismiss',
104 'yes'
105 );
106
107 wp_safe_redirect( remove_query_arg( array( 'blockspare_setup_notice_dismiss', '_blockspare_setup_notice_dismiss_nonce' ) ) );
108 exit;
109 }
110 }
111 }
112
113 /**
114 * Temporarily dismiss notice.
115 */
116 public function dismiss_notice_temporary() {
117
118 if (
119 isset( $_GET['blockspare_setup_notice_dismiss_temporary'] ) &&
120 isset( $_GET['_blockspare_setup_notice_dismiss_temporary_nonce'] )
121 ) {
122
123 if (
124 ! wp_verify_nonce(
125 wp_unslash( $_GET['_blockspare_setup_notice_dismiss_temporary_nonce'] ),
126 'blockspare_setup_notice_dismiss_temporary_nonce'
127 )
128 ) {
129 wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'blockspare' ) );
130 }
131
132 if ( ! current_user_can( 'publish_posts' ) ) {
133 wp_die( esc_html__( 'Cheatin&#8217; huh?', 'blockspare' ) );
134 }
135
136 $dismiss_notice = sanitize_text_field( wp_unslash( $_GET['blockspare_setup_notice_dismiss_temporary'] ) );
137
138 // FIX: Match current notice name dynamically instead of hardcoded 'setup'
139 if ( $this->name === $dismiss_notice ) {
140 update_user_meta(
141 $this->current_user_id,
142 'blockspare_' . $dismiss_notice . '_notice_dismiss_temporary',
143 'yes'
144 );
145
146 wp_safe_redirect( remove_query_arg( array( 'blockspare_setup_notice_dismiss_temporary', '_blockspare_setup_notice_dismiss_temporary_nonce' ) ) );
147 exit;
148 }
149 }
150 }
151 }
152
153 class Blockspare_Setup_Notice extends Blockspare_Setup {
154
155 /**
156 * Constructor.
157 */
158 public function __construct() {
159
160 $dismiss_url = wp_nonce_url(
161 add_query_arg(
162 'blockspare_setup_notice_dismiss',
163 'setup',
164 admin_url()
165 ),
166 'blockspare_setup_notice_dismiss_nonce',
167 '_blockspare_setup_notice_dismiss_nonce'
168 );
169
170 $temporary_dismiss_url = wp_nonce_url(
171 add_query_arg(
172 'blockspare_setup_notice_dismiss_temporary',
173 'setup',
174 admin_url()
175 ),
176 'blockspare_setup_notice_dismiss_temporary_nonce',
177 '_blockspare_setup_notice_dismiss_temporary_nonce'
178 );
179
180 parent::__construct(
181 'setup',
182 'info',
183 $dismiss_url,
184 $temporary_dismiss_url
185 );
186
187 $this->set_notice_time();
188 $this->set_temporary_dismiss_notice_time();
189 $this->set_dismiss_notice();
190 }
191
192 /**
193 * Set initial notice time.
194 */
195 private function set_notice_time() {
196 if ( ! get_option( 'blockspare_setup_notice_start_time' ) ) {
197 update_option( 'blockspare_setup_notice_start_time', time() );
198 }
199 }
200
201 /**
202 * Set temporary dismiss time.
203 */
204 private function set_temporary_dismiss_notice_time() {
205 if (
206 isset( $_GET['blockspare_setup_notice_dismiss_temporary'] ) &&
207 'setup' === $_GET['blockspare_setup_notice_dismiss_temporary']
208 ) {
209 update_user_meta(
210 $this->current_user_id,
211 'blockspare_setup_notice_dismiss_temporary_start_time',
212 time()
213 );
214 }
215 }
216
217 /**
218 * Set dismiss conditions.
219 */
220 public function set_dismiss_notice() {
221 $user_id = get_current_user_id();
222
223 $is_permanently_dismissed = ( 'yes' === get_user_meta( $user_id, 'blockspare_setup_notice_dismiss', true ) );
224
225 $temporary_dismiss_time = (int) get_user_meta( $user_id, 'blockspare_setup_notice_dismiss_temporary_start_time', true );
226 $is_temporarily_dismissed = ( $temporary_dismiss_time > strtotime( '-2 days' ) );
227
228 // FIX: Clean, predictable condition parsing
229 if ( $is_permanently_dismissed || $is_temporarily_dismissed ) {
230 add_filter( 'blockspare_setup_notice_dismiss', '__return_true' );
231 } else {
232 add_filter( 'blockspare_setup_notice_dismiss', '__return_false' );
233 }
234 }
235
236 /**
237 * Notice markup.
238 */
239 public function notice_markup() {
240
241 if ( ! function_exists( 'get_plugin_data' ) ) {
242 require_once ABSPATH . 'wp-admin/includes/plugin.php';
243 }
244
245 $plugin_data = get_plugin_data( BLOCKSPARE_BASE_FILE );
246 $version = isset( $plugin_data['Version'] ) ? $plugin_data['Version'] : '';
247
248 ?>
249
250 <div class="notice notice-success blockspare-notice-setup" style="padding: 18px; position: relative;">
251
252 <div style="display:flex; justify-content:space-between; gap:20px; align-items:flex-start;">
253
254 <div style="flex:1;">
255
256 <h2 style="margin:0 0 8px; font-size:18px; line-height:1.4;">
257 <?php esc_html_e( 'Welcome to BlockSpare 👋', 'blockspare' ); ?>
258 </h2>
259
260 <p style="margin:0 0 12px; font-size:14px; color:#555;">
261 <?php esc_html_e( 'Build professional news, magazine, blog, and business websites faster using ready-made Gutenberg blocks, starter templates, and content-focused layouts.', 'blockspare' ); ?>
262 </p>
263
264 <div style="display:flex; gap:10px; flex-wrap:wrap; margin-top:10px;">
265
266 <a
267 class="button button-primary"
268 href="<?php echo esc_url( admin_url( 'post-new.php?post_type=page&blockspare_show_intro=true' ) ); ?>"
269 >
270 <?php esc_html_e( 'Get Started', 'blockspare' ); ?>
271 </a>
272
273 <a
274 class="button"
275 href="<?php echo esc_url( admin_url( 'admin.php?page=blockspare' ) ); ?>"
276 >
277 <?php esc_html_e( 'Browse Templates', 'blockspare' ); ?>
278 </a>
279
280 <a
281 class="button button-secondary"
282 href="<?php echo esc_url( 'https://blockspare.com/' ); ?>"
283 target="_blank"
284 >
285 <?php esc_html_e( 'Learn More', 'blockspare' ); ?>
286 </a>
287
288 </div>
289
290 <?php if ( $version ) : ?>
291 <p style="margin-top:10px; font-size:12px; color:#888;">
292 <?php echo esc_html( 'Version ' . $version ); ?>
293 </p>
294 <?php endif; ?>
295
296 </div>
297
298 <div style="min-width:120px; text-align:right;">
299
300 <div style="font-size:12px; color:#777; margin-bottom:8px;">
301 <?php esc_html_e( 'Quick Setup', 'blockspare' ); ?>
302 </div>
303
304 <div style="font-size:11px; color:#999;">
305 <?php esc_html_e( 'Takes less than 2 minutes', 'blockspare' ); ?>
306 </div>
307
308 </div>
309
310 </div>
311
312 <a
313 class="notice-dismiss"
314 href="<?php echo esc_url( $this->dismiss_url ); ?>"
315 ></a>
316
317 </div>
318
319 <?php
320 }
321 }
322
323 /**
324 * Initialize notice after WordPress admin loads.
325 */
326 function blockspare_setup_notice_init() {
327
328 if ( ! is_admin() ) {
329 return;
330 }
331
332 new Blockspare_Setup_Notice();
333 }
334
335 add_action( 'admin_init', 'blockspare_setup_notice_init' );