| 1 |
<?php |
| 2 |
// Exit if accessed directly. |
| 3 |
defined( 'ABSPATH' ) || exit; |
| 4 |
|
| 5 |
class Blockspare_Upgrade_Notice extends Blockspare_Setup { |
| 6 |
|
| 7 |
/** |
| 8 |
* Constructor. |
| 9 |
*/ |
| 10 |
public function __construct() { |
| 11 |
|
| 12 |
// FIX: Replaced 'blockspare_notice_dismiss' with 'blockspare_setup_notice_dismiss' to match parent architecture |
| 13 |
$dismiss_url = wp_nonce_url( |
| 14 |
add_query_arg( |
| 15 |
'blockspare_setup_notice_dismiss', |
| 16 |
'upgrade', |
| 17 |
admin_url() |
| 18 |
), |
| 19 |
'blockspare_upgrade_notice_dismiss_nonce', |
| 20 |
'_blockspare_upgrade_notice_dismiss_nonce' |
| 21 |
); |
| 22 |
|
| 23 |
$temporary_dismiss_url = wp_nonce_url( |
| 24 |
add_query_arg( |
| 25 |
'blockspare_setup_notice_dismiss_temporary', |
| 26 |
'upgrade', |
| 27 |
admin_url() |
| 28 |
), |
| 29 |
'blockspare_upgrade_notice_dismiss_temporary_nonce', |
| 30 |
'_blockspare_upgrade_notice_dismiss_temporary_nonce' |
| 31 |
); |
| 32 |
|
| 33 |
parent::__construct( |
| 34 |
'upgrade', |
| 35 |
'info', |
| 36 |
$dismiss_url, |
| 37 |
$temporary_dismiss_url |
| 38 |
); |
| 39 |
|
| 40 |
$this->set_notice_time(); |
| 41 |
$this->set_temporary_dismiss_notice_time(); |
| 42 |
$this->set_dismiss_notice(); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Set initial notice time. |
| 47 |
*/ |
| 48 |
private function set_notice_time() { |
| 49 |
if ( ! get_option( 'blockspare_upgrade_notice_start_time' ) ) { |
| 50 |
update_option( 'blockspare_upgrade_notice_start_time', time() ); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Set temporary dismiss time. |
| 56 |
*/ |
| 57 |
private function set_temporary_dismiss_notice_time() { |
| 58 |
// FIX: Aligned parameter string check with parent class |
| 59 |
if ( |
| 60 |
isset( $_GET['blockspare_setup_notice_dismiss_temporary'] ) && |
| 61 |
'upgrade' === $_GET['blockspare_setup_notice_dismiss_temporary'] |
| 62 |
) { |
| 63 |
update_user_meta( |
| 64 |
$this->current_user_id, |
| 65 |
'blockspare_upgrade_notice_dismiss_temporary_start_time', |
| 66 |
time() |
| 67 |
); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Set dismiss conditions. |
| 73 |
*/ |
| 74 |
public function set_dismiss_notice() { |
| 75 |
$user_id = get_current_user_id(); |
| 76 |
|
| 77 |
$is_permanently_dismissed = ( 'yes' === get_user_meta( $user_id, 'blockspare_upgrade_notice_dismiss', true ) ); |
| 78 |
|
| 79 |
$temporary_dismiss_time = (int) get_user_meta( $user_id, 'blockspare_upgrade_notice_dismiss_temporary_start_time', true ); |
| 80 |
$is_temporarily_dismissed = ( $temporary_dismiss_time > strtotime( '-2 days' ) ); |
| 81 |
|
| 82 |
// FIX: Evaluates user meta correctly without loops or instant expiration loops |
| 83 |
if ( $is_permanently_dismissed || $is_temporarily_dismissed ) { |
| 84 |
add_filter( 'blockspare_upgrade_notice_dismiss', '__return_true' ); |
| 85 |
} else { |
| 86 |
add_filter( 'blockspare_upgrade_notice_dismiss', '__return_false' ); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Notice markup. |
| 92 |
*/ |
| 93 |
public function notice_markup() { |
| 94 |
?> |
| 95 |
<div class="notice notice-info blockspare-notice-upgrade" style="padding:24px; position:relative; border-left:4px solid #2271b1; background:#fff;"> |
| 96 |
|
| 97 |
<div style="display:flex; justify-content:space-between; gap:28px; align-items:flex-start; flex-wrap:wrap;"> |
| 98 |
|
| 99 |
<div style="flex:1; min-width:300px;"> |
| 100 |
|
| 101 |
<div style="display:inline-block; background:#e8f2ff; color:#2271b1; padding:4px 10px; border-radius:30px; font-size:12px; font-weight:600; margin-bottom:14px;"> |
| 102 |
<?php esc_html_e( 'Upgrade Available', 'blockspare' ); ?> |
| 103 |
</div> |
| 104 |
|
| 105 |
<h2 style="margin:0 0 12px; font-size:24px; line-height:1.4; font-weight:700;"> |
| 106 |
<?php esc_html_e( 'Unlock More Power with Blockspare Pro', 'blockspare' ); ?> |
| 107 |
</h2> |
| 108 |
|
| 109 |
<p style="margin:0 0 16px; font-size:14px; color:#555; max-width:920px; line-height:1.8;"> |
| 110 |
<?php esc_html_e( 'Get access to premium templates, advanced post layouts, extra design blocks, and more control over how your content looks. Blockspare Pro helps you build faster and create richer pages with less effort.', 'blockspare' ); ?> |
| 111 |
</p> |
| 112 |
|
| 113 |
<div style="display:flex; flex-wrap:wrap; gap:8px; margin-bottom:18px;"> |
| 114 |
|
| 115 |
<span style="background:#f6f7f7; padding:7px 12px; border-radius:5px; font-size:12px;"> |
| 116 |
<?php esc_html_e( 'Premium Templates', 'blockspare' ); ?> |
| 117 |
</span> |
| 118 |
|
| 119 |
<span style="background:#f6f7f7; padding:7px 12px; border-radius:5px; font-size:12px;"> |
| 120 |
<?php esc_html_e( 'Advanced Post Layouts', 'blockspare' ); ?> |
| 121 |
</span> |
| 122 |
|
| 123 |
<span style="background:#f6f7f7; padding:7px 12px; border-radius:5px; font-size:12px;"> |
| 124 |
<?php esc_html_e( 'More Blocks & Sections', 'blockspare' ); ?> |
| 125 |
</span> |
| 126 |
|
| 127 |
<span style="background:#f6f7f7; padding:7px 12px; border-radius:5px; font-size:12px;"> |
| 128 |
<?php esc_html_e( 'Extra Design Controls', 'blockspare' ); ?> |
| 129 |
</span> |
| 130 |
|
| 131 |
<span style="background:#f6f7f7; padding:7px 12px; border-radius:5px; font-size:12px;"> |
| 132 |
<?php esc_html_e( 'Faster Website Building', 'blockspare' ); ?> |
| 133 |
</span> |
| 134 |
|
| 135 |
</div> |
| 136 |
|
| 137 |
<div style="display:flex; flex-wrap:wrap; gap:10px; align-items:center;"> |
| 138 |
|
| 139 |
<a |
| 140 |
class="button button-primary" |
| 141 |
href="<?php echo esc_url( $this->pricing_url ); ?>" |
| 142 |
target="_blank" |
| 143 |
rel="noopener noreferrer" |
| 144 |
> |
| 145 |
<?php esc_html_e( 'Upgrade to Pro', 'blockspare' ); ?> |
| 146 |
</a> |
| 147 |
|
| 148 |
<a |
| 149 |
class="button" |
| 150 |
href="<?php echo esc_url( 'https://www.blockspare.com/' ); ?>" |
| 151 |
target="_blank" |
| 152 |
rel="noopener noreferrer" |
| 153 |
> |
| 154 |
<?php esc_html_e( 'View Features', 'blockspare' ); ?> |
| 155 |
</a> |
| 156 |
|
| 157 |
<a |
| 158 |
class="button button-secondary plain" |
| 159 |
href="<?php echo esc_url( $this->temporary_dismiss_url ); ?>" |
| 160 |
> |
| 161 |
<?php esc_html_e( 'Maybe later', 'blockspare' ); ?> |
| 162 |
</a> |
| 163 |
|
| 164 |
<a |
| 165 |
class="button button-secondary plain" |
| 166 |
href="<?php echo esc_url( 'https://afthemes.com/supports/' ); ?>" |
| 167 |
target="_blank" |
| 168 |
rel="noopener noreferrer" |
| 169 |
> |
| 170 |
<?php esc_html_e( 'Need help?', 'blockspare' ); ?> |
| 171 |
</a> |
| 172 |
|
| 173 |
</div> |
| 174 |
|
| 175 |
</div> |
| 176 |
|
| 177 |
<div style="width:240px; background:#f8fbff; border:1px solid #dcdcde; border-radius:12px; padding:18px;"> |
| 178 |
|
| 179 |
<div style="font-size:13px; font-weight:600; color:#2271b1; margin-bottom:12px;"> |
| 180 |
<?php esc_html_e( 'Why upgrade?', 'blockspare' ); ?> |
| 181 |
</div> |
| 182 |
|
| 183 |
<ul style="margin:0; padding-left:18px; color:#555; line-height:1.8; font-size:13px;"> |
| 184 |
<li><?php esc_html_e( 'Access premium layouts and demos', 'blockspare' ); ?></li> |
| 185 |
<li><?php esc_html_e( 'Create richer post displays', 'blockspare' ); ?></li> |
| 186 |
<li><?php esc_html_e( 'Get more design flexibility', 'blockspare' ); ?></li> |
| 187 |
<li><?php esc_html_e( 'Build pages faster with less effort', 'blockspare' ); ?></li> |
| 188 |
</ul> |
| 189 |
|
| 190 |
</div> |
| 191 |
|
| 192 |
</div> |
| 193 |
|
| 194 |
<a class="blockspare-notice-dismiss notice-dismiss" href="<?php echo esc_url( $this->dismiss_url ); ?>"></a> |
| 195 |
</div> |
| 196 |
<?php |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
/** |
| 201 |
* Initialize notice. |
| 202 |
*/ |
| 203 |
function blockspare_upgrade_notice_init() { |
| 204 |
|
| 205 |
if ( ! is_admin() ) { |
| 206 |
return; |
| 207 |
} |
| 208 |
|
| 209 |
new Blockspare_Upgrade_Notice(); |
| 210 |
} |
| 211 |
|
| 212 |
add_action( 'admin_init', 'blockspare_upgrade_notice_init' ); |