| 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 25 confirmed opt-ins |
| 34 |
// |
| 35 |
// The threshold used to be 3. Three confirmations is a site that has |
| 36 |
// barely started; asking for a public review at that point is asking |
| 37 |
// someone to vouch for something they have not seen work yet. |
| 38 |
if ( ( time() - $installed_at ) < DAY_IN_SECONDS * 10 ) { |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
if ( $confirmed_optins < 25 ) { |
| 43 |
return; |
| 44 |
} |
| 45 |
|
| 46 |
if ( $dismissed ) { |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
if ( $remind_later > 0 && ( time() < $remind_later ) ) { |
| 51 |
return; |
| 52 |
} |
| 53 |
|
| 54 |
// Max 2 reminders |
| 55 |
if ( $remind_count >= 2 ) { |
| 56 |
return; |
| 57 |
} |
| 58 |
|
| 59 |
// Claim this screen. The credit-link notice runs later on the same hook |
| 60 |
// and stands down when it sees this — asking a site owner for two |
| 61 |
// favours at once is how a plugin earns a one-star review, and the |
| 62 |
// review request is the more valuable of the two. |
| 63 |
$GLOBALS['f12_doi_review_notice_shown'] = true; |
| 64 |
|
| 65 |
?> |
| 66 |
<div class="notice notice-info is-dismissible f12-cf7-doubleoptin-review-notice"> |
| 67 |
<p> |
| 68 |
<?php printf( |
| 69 |
wp_kses( |
| 70 |
/* translators: %d: number of confirmed opt-ins. */ |
| 71 |
__( |
| 72 |
'<strong>Double Opt-In for WordPress</strong> has already confirmed <strong>%d email subscriptions</strong>. Would you support us with a quick review?', |
| 73 |
'double-opt-in' |
| 74 |
), |
| 75 |
array( 'strong' => array() ) |
| 76 |
), |
| 77 |
(int) $confirmed_optins |
| 78 |
); ?> |
| 79 |
</p> |
| 80 |
<p> |
| 81 |
<a href="https://wordpress.org/support/plugin/double-opt-in/reviews/#new-post" |
| 82 |
target="_blank" |
| 83 |
class="button button-primary"> |
| 84 |
<?php _e( 'Leave a review now', 'double-opt-in' ); ?> |
| 85 |
</a> |
| 86 |
<?php |
| 87 |
// The only path out of this notice used to be a public review. |
| 88 |
// Someone who is unhappy has no other outlet, so the feedback |
| 89 |
// lands as a one-star rating that nobody can answer. This gives |
| 90 |
// them somewhere to say it to us instead. |
| 91 |
?> |
| 92 |
<a href="<?php echo esc_url( get_feedback_url( 'review-notice' ) ); ?>" |
| 93 |
target="_blank" |
| 94 |
rel="noopener" |
| 95 |
class="button"> |
| 96 |
<?php esc_html_e( 'Something not working? Tell us', 'double-opt-in' ); ?> |
| 97 |
</a> |
| 98 |
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'f12_cf7_doubleoptin_review_remind', '1' ), 'doi_review_action' ) ); ?>" |
| 99 |
class="button"> |
| 100 |
<?php _e( 'Remind me later', 'double-opt-in' ); ?> |
| 101 |
</a> |
| 102 |
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'f12_cf7_doubleoptin_review_dismissed', '1' ), 'doi_review_action' ) ); ?>" |
| 103 |
class="button"> |
| 104 |
<?php _e( "Don't ask again", 'double-opt-in' ); ?> |
| 105 |
</a> |
| 106 |
</p> |
| 107 |
</div> |
| 108 |
<?php |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Handle review notice actions (dismiss / remind later). |
| 113 |
*/ |
| 114 |
function f12_cf7_doubleoptin_handle_review_actions() { |
| 115 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 116 |
return; |
| 117 |
} |
| 118 |
|
| 119 |
$is_dismiss = isset( $_GET['f12_cf7_doubleoptin_review_dismissed'] ); |
| 120 |
$is_remind = isset( $_GET['f12_cf7_doubleoptin_review_remind'] ); |
| 121 |
|
| 122 |
if ( ! $is_dismiss && ! $is_remind ) { |
| 123 |
return; |
| 124 |
} |
| 125 |
|
| 126 |
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), 'doi_review_action' ) ) { |
| 127 |
return; |
| 128 |
} |
| 129 |
|
| 130 |
if ( $is_dismiss ) { |
| 131 |
update_option( 'f12_cf7_doubleoptin_review_dismissed', true ); |
| 132 |
} |
| 133 |
|
| 134 |
if ( $is_remind ) { |
| 135 |
$remind_count = (int) get_option( 'f12_cf7_doubleoptin_review_remind_count', 0 ); |
| 136 |
update_option( 'f12_cf7_doubleoptin_review_remind_later', time() + DAY_IN_SECONDS * 7 ); |
| 137 |
update_option( 'f12_cf7_doubleoptin_review_remind_count', $remind_count + 1 ); |
| 138 |
} |
| 139 |
|
| 140 |
// Redirect to remove query parameters from URL |
| 141 |
wp_safe_redirect( remove_query_arg( [ 'f12_cf7_doubleoptin_review_dismissed', 'f12_cf7_doubleoptin_review_remind', '_wpnonce' ] ) ); |
| 142 |
exit; |
| 143 |
} |
| 144 |
} |
| 145 |
|