| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
// Prevent double-registration when Free + Pro are both active |
| 10 |
if ( ! function_exists( __NAMESPACE__ . '\\f12_cf7_doubleoptin_maybe_show_review_notice' ) ) { |
| 11 |
|
| 12 |
add_action( 'admin_notices', __NAMESPACE__ . '\\f12_cf7_doubleoptin_maybe_show_review_notice' ); |
| 13 |
add_action( 'admin_init', __NAMESPACE__ . '\\f12_cf7_doubleoptin_handle_review_actions' ); |
| 14 |
|
| 15 |
/** |
| 16 |
* Show review notice if conditions are met. |
| 17 |
*/ |
| 18 |
function f12_cf7_doubleoptin_maybe_show_review_notice() { |
| 19 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 20 |
return; |
| 21 |
} |
| 22 |
|
| 23 |
$installed_at = (int) get_option( 'f12_cf7_doubleoptin_installed_at', time() ); |
| 24 |
$optin_counters = get_option( 'f12_cf7_doubleoptin_telemetry_counters', [] ); |
| 25 |
$confirmed_optins = isset( $optin_counters['confirmed_optins'] ) ? (int) $optin_counters['confirmed_optins'] : 0; |
| 26 |
|
| 27 |
$dismissed = get_option( 'f12_cf7_doubleoptin_review_dismissed', false ); |
| 28 |
$remind_later = (int) get_option( 'f12_cf7_doubleoptin_review_remind_later', 0 ); |
| 29 |
$remind_count = (int) get_option( 'f12_cf7_doubleoptin_review_remind_count', 0 ); |
| 30 |
|
| 31 |
// Conditions: |
| 32 |
// - installed for at least 10 days |
| 33 |
// - at least 3 confirmed opt-ins |
| 34 |
if ( ( time() - $installed_at ) < DAY_IN_SECONDS * 10 ) { |
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
if ( $confirmed_optins < 3 ) { |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
if ( $dismissed ) { |
| 43 |
return; |
| 44 |
} |
| 45 |
|
| 46 |
if ( $remind_later > 0 && ( time() < $remind_later ) ) { |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
// Max 2 reminders |
| 51 |
if ( $remind_count >= 2 ) { |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
?> |
| 56 |
<div class="notice notice-info is-dismissible f12-cf7-doubleoptin-review-notice"> |
| 57 |
<p> |
| 58 |
<?php printf( |
| 59 |
__( |
| 60 |
'<strong>Double Opt-In for WordPress</strong> has already confirmed <strong>%d email subscriptions</strong>. Would you support us with a quick review?', |
| 61 |
'double-opt-in' |
| 62 |
), |
| 63 |
$confirmed_optins |
| 64 |
); ?> |
| 65 |
</p> |
| 66 |
<p> |
| 67 |
<a href="https://wordpress.org/support/plugin/double-opt-in/reviews/#new-post" |
| 68 |
target="_blank" |
| 69 |
class="button button-primary"> |
| 70 |
<?php _e( 'Leave a review now', 'double-opt-in' ); ?> |
| 71 |
</a> |
| 72 |
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'f12_cf7_doubleoptin_review_remind', '1' ), 'doi_review_action' ) ); ?>" |
| 73 |
class="button"> |
| 74 |
<?php _e( 'Remind me later', 'double-opt-in' ); ?> |
| 75 |
</a> |
| 76 |
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'f12_cf7_doubleoptin_review_dismissed', '1' ), 'doi_review_action' ) ); ?>" |
| 77 |
class="button"> |
| 78 |
<?php _e( "Don't ask again", 'double-opt-in' ); ?> |
| 79 |
</a> |
| 80 |
</p> |
| 81 |
</div> |
| 82 |
<?php |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Handle review notice actions (dismiss / remind later). |
| 87 |
*/ |
| 88 |
function f12_cf7_doubleoptin_handle_review_actions() { |
| 89 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 90 |
return; |
| 91 |
} |
| 92 |
|
| 93 |
$is_dismiss = isset( $_GET['f12_cf7_doubleoptin_review_dismissed'] ); |
| 94 |
$is_remind = isset( $_GET['f12_cf7_doubleoptin_review_remind'] ); |
| 95 |
|
| 96 |
if ( ! $is_dismiss && ! $is_remind ) { |
| 97 |
return; |
| 98 |
} |
| 99 |
|
| 100 |
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), 'doi_review_action' ) ) { |
| 101 |
return; |
| 102 |
} |
| 103 |
|
| 104 |
if ( $is_dismiss ) { |
| 105 |
update_option( 'f12_cf7_doubleoptin_review_dismissed', true ); |
| 106 |
} |
| 107 |
|
| 108 |
if ( $is_remind ) { |
| 109 |
$remind_count = (int) get_option( 'f12_cf7_doubleoptin_review_remind_count', 0 ); |
| 110 |
update_option( 'f12_cf7_doubleoptin_review_remind_later', time() + DAY_IN_SECONDS * 7 ); |
| 111 |
update_option( 'f12_cf7_doubleoptin_review_remind_count', $remind_count + 1 ); |
| 112 |
} |
| 113 |
|
| 114 |
// Redirect to remove query parameters from URL |
| 115 |
wp_safe_redirect( remove_query_arg( [ 'f12_cf7_doubleoptin_review_dismissed', 'f12_cf7_doubleoptin_review_remind', '_wpnonce' ] ) ); |
| 116 |
exit; |
| 117 |
} |
| 118 |
} |
| 119 |
|