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