| 1 |
<?php |
| 2 |
// Exit if accessed directly. |
| 3 |
defined( 'ABSPATH' ) || exit; |
| 4 |
|
| 5 |
class Blockspare_Review_Notice extends Blockspare_Setup { |
| 6 |
|
| 7 |
/** |
| 8 |
* Constructor. |
| 9 |
*/ |
| 10 |
public function __construct() { |
| 11 |
|
| 12 |
// Setup dismissal arguments mapped to 'review' action |
| 13 |
$dismiss_url = wp_nonce_url( |
| 14 |
add_query_arg( |
| 15 |
'blockspare_setup_notice_dismiss', |
| 16 |
'review', |
| 17 |
admin_url() |
| 18 |
), |
| 19 |
'blockspare_review_notice_dismiss_nonce', |
| 20 |
'_blockspare_review_notice_dismiss_nonce' |
| 21 |
); |
| 22 |
|
| 23 |
$temporary_dismiss_url = wp_nonce_url( |
| 24 |
add_query_arg( |
| 25 |
'blockspare_setup_notice_dismiss_temporary', |
| 26 |
'review', |
| 27 |
admin_url() |
| 28 |
), |
| 29 |
'blockspare_review_notice_dismiss_temporary_nonce', |
| 30 |
'_blockspare_review_notice_dismiss_temporary_nonce' |
| 31 |
); |
| 32 |
|
| 33 |
parent::__construct( |
| 34 |
'review', |
| 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 (e.g., to delay showing it right after installation). |
| 47 |
*/ |
| 48 |
private function set_notice_time() { |
| 49 |
if ( ! get_option( 'blockspare_review_notice_start_time' ) ) { |
| 50 |
update_option( 'blockspare_review_notice_start_time', time() ); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Set temporary dismiss time (Snooze). |
| 56 |
*/ |
| 57 |
private function set_temporary_dismiss_notice_time() { |
| 58 |
if ( |
| 59 |
isset( $_GET['blockspare_setup_notice_dismiss_temporary'] ) && |
| 60 |
'review' === $_GET['blockspare_setup_notice_dismiss_temporary'] |
| 61 |
) { |
| 62 |
update_user_meta( |
| 63 |
$this->current_user_id, |
| 64 |
'blockspare_review_notice_dismiss_temporary_start_time', |
| 65 |
time() |
| 66 |
); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Set dismiss conditions. |
| 72 |
*/ |
| 73 |
public function set_dismiss_notice() { |
| 74 |
$user_id = get_current_user_id(); |
| 75 |
|
| 76 |
$is_permanently_dismissed = ( 'yes' === get_user_meta( $user_id, 'blockspare_review_notice_dismiss', true ) ); |
| 77 |
|
| 78 |
$temporary_dismiss_time = (int) get_user_meta( $user_id, 'blockspare_review_notice_dismiss_temporary_start_time', true ); |
| 79 |
// Review notices usually have a longer snooze period (e.g., 7 days instead of 2) |
| 80 |
$is_temporarily_dismissed = ( $temporary_dismiss_time > strtotime( '-7 days' ) ); |
| 81 |
|
| 82 |
// Delay displaying the review notice until the plugin has been active for at least 3 days |
| 83 |
$start_time = (int) get_option( 'blockspare_upgrade_notice_start_time', time() ); |
| 84 |
// $is_too_early = ( $start_time > strtotime( '-3 days' ) ); |
| 85 |
$is_too_early = ( $start_time > strtotime( '1 min' ) ); |
| 86 |
|
| 87 |
if ( $is_permanently_dismissed || $is_temporarily_dismissed || $is_too_early ) { |
| 88 |
add_filter( 'blockspare_review_notice_dismiss', '__return_true' ); |
| 89 |
} else { |
| 90 |
add_filter( 'blockspare_review_notice_dismiss', '__return_false' ); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Notice markup. |
| 96 |
*/ |
| 97 |
public function notice_markup() { |
| 98 |
$review_url = 'https://wordpress.org/support/plugin/blockspare/reviews/?filter=5'; |
| 99 |
?> |
| 100 |
<div class="notice notice-info blockspare-notice-review" style="padding:24px; position:relative; border-left:4px solid #10b981; background:#fff;"> |
| 101 |
|
| 102 |
<div style="display:flex; justify-content:space-between; gap:28px; align-items:flex-start; flex-wrap:wrap;"> |
| 103 |
|
| 104 |
<div style="flex:1; min-width:300px;"> |
| 105 |
|
| 106 |
<div style="display:inline-flex; align-items:center; gap:4px; background:#f0fdf4; color:#15803d; padding:4px 12px; border-radius:30px; font-size:12px; font-weight:600; margin-bottom:14px;"> |
| 107 |
<span class="dashicons dashicons-star-filled" style="font-size:14px; width:14px; height:14px; color:#f59e0b;"></span> |
| 108 |
<?php esc_html_e( 'Loving Blockspare?', 'blockspare' ); ?> |
| 109 |
</div> |
| 110 |
|
| 111 |
<h2 style="margin:0 0 12px; font-size:24px; line-height:1.4; font-weight:700; color:#1e293b;"> |
| 112 |
<?php esc_html_e( 'Share Your Experience with the WordPress Community!', 'blockspare' ); ?> |
| 113 |
</h2> |
| 114 |
|
| 115 |
<p style="margin:0 0 20px; font-size:14px; color:#475569; max-width:920px; line-height:1.8;"> |
| 116 |
<?php esc_html_e( 'We hope Blockspare is helping you build beautiful web pages effortlessly. As an independent team, your feedback keeps us motivated to push new features, keep updates free, and maintain great performance. If you enjoy using it, would you mind spending 1 minute to leave us a review?', 'blockspare' ); ?> |
| 117 |
</p> |
| 118 |
|
| 119 |
<div style="display:flex; flex-wrap:wrap; gap:12px; align-items:center;"> |
| 120 |
|
| 121 |
<a |
| 122 |
class="button button-primary" |
| 123 |
style="background:#10b981; border-color:#10b981; box-shadow:none; text-shadow:none;" |
| 124 |
href="<?php echo esc_url( $review_url ); ?>" |
| 125 |
target="_blank" |
| 126 |
rel="noopener noreferrer" |
| 127 |
> |
| 128 |
<?php esc_html_e( 'Leave a Review', 'blockspare' ); ?> |
| 129 |
</a> |
| 130 |
|
| 131 |
<a |
| 132 |
class="button" |
| 133 |
href="<?php echo esc_url( $this->temporary_dismiss_url ); ?>" |
| 134 |
> |
| 135 |
<?php esc_html_e( 'Maybe later, remind me', 'blockspare' ); ?> |
| 136 |
</a> |
| 137 |
|
| 138 |
<a |
| 139 |
class="button" |
| 140 |
style="color:#64748b; text-decoration:none;" |
| 141 |
href="<?php echo esc_url( $this->dismiss_url ); ?>" |
| 142 |
> |
| 143 |
<?php esc_html_e( 'No thanks, don\'t show again', 'blockspare' ); ?> |
| 144 |
</a> |
| 145 |
|
| 146 |
</div> |
| 147 |
|
| 148 |
</div> |
| 149 |
|
| 150 |
<div style="width:240px; background:#f8fafc; border:1px solid #e2e8f0; border-radius:12px; padding:18px; text-align:center;"> |
| 151 |
|
| 152 |
<div style="font-size:32px; line-height:1; margin-bottom:10px; color:#f59e0b; display:flex; justify-content:center; gap:2px;"> |
| 153 |
<span class="dashicons dashicons-star-filled" style="font-size:28px; width:28px; height:28px;"></span> |
| 154 |
<span class="dashicons dashicons-star-filled" style="font-size:28px; width:28px; height:28px;"></span> |
| 155 |
<span class="dashicons dashicons-star-filled" style="font-size:28px; width:28px; height:28px;"></span> |
| 156 |
<span class="dashicons dashicons-star-filled" style="font-size:28px; width:28px; height:28px;"></span> |
| 157 |
<span class="dashicons dashicons-star-filled" style="font-size:28px; width:28px; height:28px;"></span> |
| 158 |
</div> |
| 159 |
|
| 160 |
<div style="font-size:13px; font-weight:600; color:#334155; margin-bottom:6px;"> |
| 161 |
<?php esc_html_e( 'Help Us Grow', 'blockspare' ); ?> |
| 162 |
</div> |
| 163 |
|
| 164 |
<p style="margin:0; color:#64748b; line-height:1.5; font-size:12px;"> |
| 165 |
<?php esc_html_e( 'Every review brings valuable visibility to our free plugin.', 'blockspare' ); ?> |
| 166 |
</p> |
| 167 |
|
| 168 |
</div> |
| 169 |
|
| 170 |
</div> |
| 171 |
|
| 172 |
<a class="blockspare-notice-dismiss notice-dismiss" href="<?php echo esc_url( $this->dismiss_url ); ?>"></a> |
| 173 |
</div> |
| 174 |
<?php |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
/** |
| 179 |
* Initialize notice. |
| 180 |
*/ |
| 181 |
function blockspare_review_notice_init() { |
| 182 |
|
| 183 |
if ( ! is_admin() ) { |
| 184 |
return; |
| 185 |
} |
| 186 |
|
| 187 |
new Blockspare_Review_Notice(); |
| 188 |
} |
| 189 |
|
| 190 |
add_action( 'admin_init', 'blockspare_review_notice_init' ); |