Contracts
4 years ago
Enum
4 years ago
Events
2 years ago
Helpers
4 years ago
Repositories
4 years ago
TrackingData
2 years ago
AccessToken.php
4 years ago
AdminActionHandler.php
4 years ago
AdminSettings.php
4 years ago
TrackClient.php
4 years ago
TrackJob.php
4 years ago
TrackJobScheduler.php
4 years ago
TrackRegisterer.php
4 years ago
TrackingServiceProvider.php
2 years ago
UsageTrackingOnBoarding.php
4 years ago
UsageTrackingOnBoarding.php
151 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Tracking; |
| 4 | |
| 5 | use Give\Onboarding\Setup\PageView; |
| 6 | use Give\Tracking\Repositories\Settings; |
| 7 | use Give_Admin_Settings; |
| 8 | |
| 9 | /** |
| 10 | * Class OnBoarding |
| 11 | * @package Give\Tracking |
| 12 | * |
| 13 | * This class uses to setup notice nag to website administrator if admin is not opt in for usage tracking and gives admin an option to directly opt-in. |
| 14 | * |
| 15 | * @since 2.10.0 |
| 16 | */ |
| 17 | class UsageTrackingOnBoarding |
| 18 | { |
| 19 | /** |
| 20 | * @var Settings |
| 21 | */ |
| 22 | private $settings; |
| 23 | |
| 24 | /** |
| 25 | * UsageTrackingOnBoarding constructor. |
| 26 | * |
| 27 | * @param Settings $settings |
| 28 | */ |
| 29 | public function __construct(Settings $settings) |
| 30 | { |
| 31 | $this->settings = $settings; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Register notice. |
| 36 | * |
| 37 | * @since 2.10.0 |
| 38 | */ |
| 39 | public function addNotice() |
| 40 | { |
| 41 | if ( ! $this->canShowNotice()) { |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | echo $this->getNotice(true); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Get option name of notice. |
| 50 | * |
| 51 | * We use this option key to disable notice nag for specific user for a interval. |
| 52 | * |
| 53 | * @since 2.10.0 |
| 54 | * @return string |
| 55 | */ |
| 56 | public function getNoticeOptionKey() |
| 57 | { |
| 58 | return give()->notices->get_notice_key('usage-tracking-nag', 'permanent'); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Get notice. |
| 63 | * |
| 64 | * @since 2.10.0 |
| 65 | * |
| 66 | * @param bool $wrapper |
| 67 | * |
| 68 | * @return string |
| 69 | */ |
| 70 | public function getNotice($wrapper = false) |
| 71 | { |
| 72 | /* @var PageView $pageView */ |
| 73 | $pageView = give()->make(PageView::class); |
| 74 | |
| 75 | $notice = $pageView->render_template( |
| 76 | 'row-item', |
| 77 | [ |
| 78 | 'icon' => $pageView->image('hands-in.svg'), |
| 79 | 'class' => ! $wrapper ? 'usage-tracking' : '', |
| 80 | 'icon_alt' => esc_html__('Anonymous usage tracking icon', 'give'), |
| 81 | 'title' => esc_html__('Help GiveWP improve your fundraising experience', 'give'), |
| 82 | 'description' => sprintf( |
| 83 | '%1$s<br><br><a href="https://go.givewp.com/plugin-optin" class="learn-more-link" target="_blank">%2$s</a>', |
| 84 | esc_html__( |
| 85 | 'Can you help improve GiveWP? With your permission, the GiveWP team uses non-sensitive data from plugin users to optimize donation form conversion rates, increase average donation amounts, and streamline the fundraising experience. This data is never shared with any third party.', |
| 86 | 'give' |
| 87 | ), |
| 88 | esc_html__( |
| 89 | 'Learn more about how GiveWP respects user and donor privacy while improving the plugin >', |
| 90 | 'give' |
| 91 | ) |
| 92 | ), |
| 93 | 'action' => sprintf( |
| 94 | '<a class="button" href="%1$s">%2$s</a><div class="sub-links"><a href="%3$s" title="%7$s">%4$s</a><a href="%5$s">%6$s</a></div>', |
| 95 | esc_url(add_query_arg(['give_action' => 'opt_in_into_tracking'])), |
| 96 | esc_html__('Glad to Help', 'give'), |
| 97 | esc_url(add_query_arg(['give_action' => 'hide_opt_in_notice_shortly'])), |
| 98 | esc_html__('Not Right Now', 'give'), |
| 99 | esc_url(add_query_arg(['give_action' => 'hide_opt_in_notice_permanently'])), |
| 100 | esc_html__('Dismiss Forever', 'give'), |
| 101 | esc_html__('Disable notice for 48 hours', 'give') |
| 102 | ), |
| 103 | ] |
| 104 | ); |
| 105 | |
| 106 | return $wrapper ? sprintf( |
| 107 | '<div class="usage-tracking notice"><section><main>%1$s</main></section></div>', |
| 108 | $notice |
| 109 | ) : $notice; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Return whether or not user can see notice. |
| 114 | * |
| 115 | * @since 2.10.0 |
| 116 | */ |
| 117 | public function canShowNotice() |
| 118 | { |
| 119 | if ( ! current_user_can('manage_give_settings')) { |
| 120 | return false; |
| 121 | } |
| 122 | |
| 123 | $section = isset($_GET['section']) ? 'advanced-options' : ''; |
| 124 | if (Give_Admin_Settings::is_setting_page('advanced', $section)) { |
| 125 | return false; |
| 126 | } |
| 127 | |
| 128 | $optionValue = $this->settings->getUsageTrackingNoticeNagOptionValue(); |
| 129 | |
| 130 | if (is_numeric($optionValue) && ('0' === $optionValue || $optionValue > time())) { |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | return ! give_is_setting_enabled($this->settings->getUsageTrackingOptionValue()); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Disable notice. |
| 139 | * |
| 140 | * @since 2.10.0 |
| 141 | * |
| 142 | * @param int $timestamp |
| 143 | * |
| 144 | * @return bool |
| 145 | */ |
| 146 | public function disableNotice($timestamp) |
| 147 | { |
| 148 | return $this->settings->saveUsageTrackingNoticeNagOptionValue($timestamp); |
| 149 | } |
| 150 | } |
| 151 |