| 1 |
<?php |
| 2 |
add_action( 'admin_notices', 'f12_cf7_doubleoptin_maybe_show_review_notice' ); |
| 3 |
add_action( 'admin_init', 'f12_cf7_doubleoptin_handle_review_actions' ); |
| 4 |
|
| 5 |
/** |
| 6 |
* Prüft, ob die Review-Notice angezeigt werden soll. |
| 7 |
*/ |
| 8 |
function f12_cf7_doubleoptin_maybe_show_review_notice() { |
| 9 |
// Nur Admins sehen die Notice |
| 10 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 11 |
return; |
| 12 |
} |
| 13 |
|
| 14 |
$installed_at = (int) get_option( 'f12_cf7_doubleoptin_installed_at', time() ); |
| 15 |
$optin_counters = get_option( 'f12_cf7_doubleoptin_telemetry_counters', [] ); |
| 16 |
$confirmed_optins = isset( $optin_counters['confirmed_optins'] ) ? (int) $optin_counters['confirmed_optins'] : 0; |
| 17 |
|
| 18 |
$dismissed = get_option( 'f12_cf7_doubleoptin_review_dismissed', false ); |
| 19 |
$remind_later = (int) get_option( 'f12_cf7_doubleoptin_review_remind_later', 0 ); |
| 20 |
$remind_count = (int) get_option( 'f12_cf7_doubleoptin_review_remind_count', 0 ); |
| 21 |
|
| 22 |
// Bedingungen: |
| 23 |
// - mindestens 10 Tage installiert |
| 24 |
// - mindestens 20 Spamversuche blockiert |
| 25 |
if ( ( time() - $installed_at ) < DAY_IN_SECONDS * 10 ) { |
| 26 |
return; |
| 27 |
} |
| 28 |
|
| 29 |
if ( $confirmed_optins < 3 ) { |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
// Bereits dauerhaft dismissed? |
| 34 |
if ( $dismissed ) { |
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
// Reminder-Delay aktiv? |
| 39 |
if ( $remind_later > 0 && ( time() < $remind_later ) ) { |
| 40 |
return; |
| 41 |
} |
| 42 |
|
| 43 |
// Maximal 2 Wiederholungen |
| 44 |
if ( $remind_count >= 2 ) { |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
?> |
| 49 |
<div class="notice notice-info is-dismissible f12-cf7-captcha-review-notice"> |
| 50 |
<p> |
| 51 |
<?php printf( |
| 52 |
__( |
| 53 |
'<strong>Double Opt-In for WordPress</strong> has already confirmed <strong>%d email subscriptions</strong>. Would you support us with a quick review? ❤️', |
| 54 |
'double-opt-in' |
| 55 |
), |
| 56 |
$confirmed_optins |
| 57 |
); ?> |
| 58 |
</p> |
| 59 |
<p> |
| 60 |
<a href="https://wordpress.org/support/plugin/double-opt-in/reviews/#new-post" |
| 61 |
target="_blank" |
| 62 |
class="button button-primary"> |
| 63 |
<?php _e( 'Leave a review now', 'double-opt-in' ); ?> |
| 64 |
</a> |
| 65 |
<a href="<?php echo esc_url( add_query_arg( 'f12_cf7_doubleoptin_review_remind', '1' ) ); ?>" |
| 66 |
class="button"> |
| 67 |
<?php _e( 'Remind me later', 'double-opt-in' ); ?> |
| 68 |
</a> |
| 69 |
<a href="<?php echo esc_url( add_query_arg( 'f12_cf7_doubleoptin_review_dismissed', '1' ) ); ?>" |
| 70 |
class="button"> |
| 71 |
<?php _e( 'Don’t ask again', 'double-opt-in' ); ?> |
| 72 |
</a> |
| 73 |
</p> |
| 74 |
</div> |
| 75 |
<?php |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Verarbeitet Klicks auf die Links der Review-Notice. |
| 80 |
*/ |
| 81 |
function f12_cf7_doubleoptin_handle_review_actions() { |
| 82 |
if ( isset( $_GET['f12_cf7_doubleoptin_review_dismissed'] ) ) { |
| 83 |
update_option( 'f12_cf7_doubleoptin_review_dismissed', true ); |
| 84 |
} |
| 85 |
|
| 86 |
if ( isset( $_GET['f12_cf7_doubleoptin_review_remind'] ) ) { |
| 87 |
$remind_count = (int) get_option( 'f12_cf7_doubleoptin_review_remind_count', 0 ); |
| 88 |
update_option( 'f12_cf7_doubleoptin_review_remind_later', time() + DAY_IN_SECONDS * 7 ); // 7 Tage warten |
| 89 |
update_option( 'f12_cf7_doubleoptin_review_remind_count', $remind_count + 1 ); |
| 90 |
} |
| 91 |
} |
| 92 |
|