should_show()) {
return;
}
$url = static fn (string $choice): string => wp_nonce_url(
admin_url('admin-post.php?action=' . self::ACTION . '&choice=' . $choice),
self::ACTION
);
echo '
';
}
public function handle_choice(): void
{
check_admin_referer(self::ACTION);
if (! current_user_can(Plugin::capability())) {
wp_die(esc_html__('Sorry, you are not allowed to do that.', 'funnelnode'), '', ['response' => 403]);
}
$choice = sanitize_key(wp_unslash((string) ($_GET['choice'] ?? '')));
$user_id = get_current_user_id();
if ('later' === $choice) {
update_user_meta($user_id, self::USER_META, (string) (time() + self::SNOOZE));
} else {
update_user_meta($user_id, self::USER_META, 'done');
}
if ('review' === $choice) {
// phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- fixed wordpress.org URL.
wp_redirect(self::REVIEW_URL);
exit;
}
wp_safe_redirect(wp_get_referer() ?: admin_url('admin.php?page=' . Admin::MENU_SLUG));
exit;
}
private function should_show(): bool
{
if (! current_user_can(Plugin::capability())) {
return false;
}
$screen = function_exists('get_current_screen') ? get_current_screen() : null;
if (! $screen || ! str_contains((string) $screen->id, 'funnelnode')) {
return false;
}
$first = (int) get_option(self::FIRST_LEAD_OPTION);
if (! $first || time() < $first + self::DELAY) {
return false;
}
$state = (string) get_user_meta(get_current_user_id(), self::USER_META, true);
if ('done' === $state) {
return false;
}
return ! ($state !== '' && time() < (int) $state);
}
}