PluginProbe
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites / 2.6.1
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites v2.6.1
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-upgrade.php

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

218 lines 8.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
6 // Exit if accessed directly.
7 defined('ABSPATH') || exit;
8
9 class Blockspare_Notice
10 {
11 public $name;
12 public $type;
13 public $dismiss_url;
14 public $temporary_dismiss_url;
15 public $pricing_url;
16 public $current_user_id;
17
18 /**
19 * The constructor.
20 *
21 * @param string $name Notice Name.
22 * @param string $type Notice type.
23 * @param string $dismiss_url Notice permanent dismiss URL.
24 * @param string $temporary_dismiss_url Notice temporary dismiss URL.
25 *
26 * @since 1.4.7
27 *
28 */
29 public function __construct($name, $type, $dismiss_url, $temporary_dismiss_url)
30 {
31 $this->name = $name;
32 $this->type = $type;
33 $this->dismiss_url = $dismiss_url;
34 $this->temporary_dismiss_url = $temporary_dismiss_url;
35 $this->pricing_url = 'https://www.blockspare.com/pricing/';
36 $this->current_user_id = get_current_user_id();
37
38 // Notice markup.
39 add_action('admin_notices', array($this, 'notice'));
40
41 $this->dismiss_notice();
42 $this->dismiss_notice_temporary();
43 }
44
45 public function notice()
46 {
47 if (!$this->is_dismiss_notice()) {
48 $this->notice_markup();
49 }
50 }
51
52 private function is_dismiss_notice()
53 {
54 return apply_filters('blockspare_' . $this->name . '_notice_dismiss', true);
55 }
56
57 public function notice_markup()
58 {
59 echo '';
60 }
61
62 /**
63 * Hide a notice if the GET variable is set.
64 */
65 public function dismiss_notice()
66 {
67 if (isset($_GET['blockspare_notice_dismiss']) && isset($_GET['_blockspare_upgrade_notice_dismiss_nonce'])) { // WPCS: input var ok.
68 if (!wp_verify_nonce(wp_unslash($_GET['_blockspare_upgrade_notice_dismiss_nonce']), 'blockspare_upgrade_notice_dismiss_nonce')) { // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput.InputNotSanitized
69 wp_die(__('Action failed. Please refresh the page and retry.', 'blockspare')); // WPCS: xss ok.
70 }
71
72 if (!current_user_can('publish_posts')) {
73 wp_die(__('Cheatin&#8217; huh?', 'blockspare')); // WPCS: xss ok.
74 }
75
76 $dismiss_notice = sanitize_text_field(wp_unslash($_GET['blockspare_notice_dismiss']));
77
78 // Hide.
79 if ($dismiss_notice === $_GET['blockspare_notice_dismiss']) {
80 add_user_meta(get_current_user_id(), 'blockspare_' . $dismiss_notice . '_notice_dismiss', 'yes', true);
81 }
82 }
83 }
84
85 public function dismiss_notice_temporary()
86 {
87 if (isset($_GET['blockspare_notice_dismiss_temporary']) && isset($_GET['_blockspare_upgrade_notice_dismiss_temporary_nonce'])) { // WPCS: input var ok.
88 if (!wp_verify_nonce(wp_unslash($_GET['_blockspare_upgrade_notice_dismiss_temporary_nonce']), 'blockspare_upgrade_notice_dismiss_temporary_nonce')) { // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput.InputNotSanitized
89 wp_die(__('Action failed. Please refresh the page and retry.', 'blockspare')); // WPCS: xss ok.
90 }
91
92 if (!current_user_can('publish_posts')) {
93 wp_die(__('Cheatin&#8217; huh?', 'blockspare')); // WPCS: xss ok.
94 }
95
96 $dismiss_notice = sanitize_text_field(wp_unslash($_GET['blockspare_notice_dismiss_temporary']));
97
98 // Hide.
99 if ($dismiss_notice === $_GET['blockspare_notice_dismiss_temporary']) {
100 add_user_meta(get_current_user_id(), 'blockspare_' . $dismiss_notice . '_notice_dismiss_temporary', 'yes', true);
101 }
102 }
103 }
104 }
105
106
107 class Blockspare_Upgrade_Notice extends Blockspare_Notice {
108
109 public function __construct() {
110 if ( ! current_user_can( 'publish_posts' ) ) {
111 return;
112 }
113
114 $dismiss_url = wp_nonce_url(
115 add_query_arg( 'blockspare_notice_dismiss', 'upgrade', admin_url() ),
116 'blockspare_upgrade_notice_dismiss_nonce',
117 '_blockspare_upgrade_notice_dismiss_nonce'
118 );
119
120 $temporary_dismiss_url = wp_nonce_url(
121 add_query_arg( 'blockspare_notice_dismiss_temporary', 'upgrade', admin_url() ),
122 'blockspare_upgrade_notice_dismiss_temporary_nonce',
123 '_blockspare_upgrade_notice_dismiss_temporary_nonce'
124 );
125
126 parent::__construct( 'upgrade', 'info', $dismiss_url, $temporary_dismiss_url );
127
128 $this->set_notice_time();
129
130 $this->set_temporary_dismiss_notice_time();
131
132 $this->set_dismiss_notice();
133 }
134
135 private function set_notice_time() {
136 if ( ! get_option( 'blockspare_upgrade_notice_start_time' ) ) {
137 update_option( 'blockspare_upgrade_notice_start_time', time() );
138 }
139 }
140
141 private function set_temporary_dismiss_notice_time() {
142 if ( isset( $_GET['blockspare_notice_dismiss_temporary'] ) && 'upgrade' === $_GET['blockspare_notice_dismiss_temporary'] ) {
143 update_user_meta( $this->current_user_id, 'blockspare_upgrade_notice_dismiss_temporary_start_time', time() );
144 }
145 }
146
147 public function set_dismiss_notice() {
148
149 /**
150 * Do not show notice if:
151 *
152 * 1. It has not been 5 days since the plugin is activated.
153 * 2. If the user has ignored the message partially for 2 days.
154 * 3. Dismiss always if clicked on 'Dismiss' button.
155 */
156 if ( get_option( 'blockspare_upgrade_notice_start_time' ) > strtotime( '-2 days' )
157 || get_user_meta( get_current_user_id(), 'blockspare_upgrade_notice_dismiss', true )
158 || get_user_meta( get_current_user_id(), 'blockspare_upgrade_notice_dismiss_temporary_start_time', true ) > strtotime( '-2 days' )
159 ) {
160 add_filter( 'blockspare_upgrade_notice_dismiss', '__return_true' );
161 } else {
162 add_filter( 'blockspare_upgrade_notice_dismiss', '__return_false' );
163 }
164 }
165
166 public function notice_markup() {
167 ?>
168 <div class="notice notice-success blockspare-notice" >
169 <a class="blockspare-notice-dismiss notice-dismiss" href="<?php echo esc_url( $this->dismiss_url ); ?>"></a>
170 <span class="blockspare-icon-display"></span>
171
172 <?php
173 $current_user = wp_get_current_user();
174
175 printf(
176 /* Translators: %1$s current user display name., %2$s this plugin name., %3$s discount coupon code., %4$s discount percentage. */
177 esc_html__(
178 '%1$s %7$s We would appreciate it if you can %4$sgive us a 5 star rating on WordPress.org%5$s! By spreading the love, we will continue to create thrilling new features for free in the future! %6$sYou may always upgrade to %3$s to gain access to premium templates, sections and blocks. Enjoy! %8$s',
179 'blockspare'
180 ),
181 '<h2>Hello ' . esc_html( $current_user->display_name ) . ', you are awesome for using Blockspare!</h2>',
182 '<p class="notice-text"><strong>Blockspare</strong>',
183 '<strong><a target="_blank" href="https://www.blockspare.com/pricing/">Blockspare Pro</a></strong>',
184 '<strong><a href="https://wordpress.org/support/plugin/blockspare/reviews/?filter=5#new-post" target="_blank">',
185 '</a></strong>',
186 '<br>',
187 '<p>',
188 '</p>',
189 );
190 ?>
191 </p>
192
193 <div class="links">
194 <a href="https://wordpress.org/support/plugin/blockspare/reviews/?filter=5#new-post" class="button button-primary" target="_blank">
195 <span><?php esc_html_e( 'Sure thing', 'blockspare' ); ?></span>
196 </a>
197
198 <a href="<?php echo esc_url( $this->pricing_url ); ?>" class="button button-secondary" target="_blank">
199 <span><?php esc_html_e( 'Upgrade', 'blockspare' ); ?></span>
200 </a>
201
202 <a href="<?php echo esc_url( $this->temporary_dismiss_url ); ?>" class="button button-secondary plain">
203
204 <span><?php esc_html_e( 'Maybe later', 'blockspare' ); ?></span>
205 </a>
206
207 <a href="https://afthemes.com/supports/" class="button button-secondary plain" target="_blank">
208
209 <span><?php esc_html_e( 'Need help?', 'blockspare' ); ?></span>
210 </a>
211 </div>
212 </div> <!-- /blockspare-notice -->
213 <?php
214 }
215 }
216
217 new Blockspare_Upgrade_Notice();
218