1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
include_once( 'class-ts-tracker.php' );
class Wcap_TS_tracking {
public static $plugin_prefix = '';
public static $plugin_name = '';
public static $blog_post_link = '';
public static $plugin_context = '';
public static $plugin_url = '';
public static $ts_file_path = '' ;
public static $ts_plugin_locale = '';
public static $ts_settings_page = '';
public static $ts_add_setting_on_page = '';
public static $ts_add_setting_on_section = '';
public static $ts_register_setting = '';
public function __construct( $ts_plugin_prefix = '', $ts_plugin_name = '', $ts_blog_post_link = '', $ts_plugin_context = '', $ts_plugin_url = '', $setting_page = '', $add_setting = '', $setting_section = '', $setting_register = '' ) {
self::$plugin_prefix = $ts_plugin_prefix;
self::$plugin_name = $ts_plugin_name;
self::$blog_post_link = $ts_blog_post_link;
self::$plugin_url = $ts_plugin_url;
self::$ts_plugin_locale = $ts_plugin_context;
self::$ts_settings_page = $setting_page;
self::$ts_add_setting_on_page = $add_setting;
self::$ts_add_setting_on_section = $setting_section;
self::$ts_register_setting = $setting_register;
self::$ts_file_path = untrailingslashit( plugins_url( '/', __FILE__) ) ;
add_action( 'admin_notices', array( 'Wcap_TS_tracking', 'ts_track_usage_data' ) );
add_action( 'admin_footer', array( 'Wcap_TS_tracking', 'ts_admin_notices_scripts' ) );
add_action( 'wp_ajax_'.self::$plugin_prefix.'_admin_notices', array( 'Wcap_TS_tracking', 'ts_admin_notices' ) );
add_filter( 'cron_schedules', array( 'Wcap_TS_tracking', 'ts_add_cron_schedule' ) );
add_action( self::$plugin_prefix . '_add_new_settings', array( 'Wcap_TS_tracking', 'ts_add_reset_tracking_setting' ) );
add_action ( 'admin_init', array( 'Wcap_TS_tracking', 'ts_reset_tracking_setting' ) ) ;
self::ts_schedule_cron_job();
}
public static function ts_reset_tracking_setting () {
if ( isset ( $_GET [ 'ts_action' ] ) && 'reset_tracking' == $_GET [ 'ts_action' ] ) {
delete_option( self::$plugin_prefix . '_allow_tracking' );
delete_option( 'ts_tracker_last_send' );
$ts_url = remove_query_arg( 'ts_action' );
wp_safe_redirect( $ts_url );
}
}
public static function ts_add_reset_tracking_setting () {
add_settings_field(
'ts_reset_tracking',
__( 'Reset usage tracking', self::$ts_plugin_locale ),
array( 'Wcap_TS_tracking', 'ts_rereset_tracking_callback' ),
self::$ts_add_setting_on_page,
self::$ts_add_setting_on_section,
array( 'This will reset your usage tracking settings, causing it to show the opt-in banner again and not sending any data.', self::$ts_plugin_locale )
);
register_setting(
self::$ts_register_setting,
'ts_reset_tracking'
);
}
public static function ts_reset_tracking_setting_section_callback ( ) {
}
public static function ts_rereset_tracking_callback ( $args ) {
$wcap_restrict_domain_address = get_option( 'wcap_restrict_domain_address' );
$domain_value = isset( $wcap_restrict_domain_address ) ? esc_attr( $wcap_restrict_domain_address ) : '';
$ts_action = self::$ts_settings_page . "&ts_action=reset_tracking";
printf( '<a href="'.$ts_action.'" class="button button-large reset_tracking">Reset</a>' );
$html = '<label for="wcap_restrict_domain_address_label"> ' . $args[0] . '</label>';
echo $html;
}
public static function ts_add_cron_schedule( $schedules ) {
$schedules[ 'once_in_week' ] = array(
'interval' => 604800,
'display' => __( 'Once in a Week', self::$ts_plugin_locale )
);
return $schedules;
}
public static function ts_schedule_cron_job () {
if ( ! wp_next_scheduled( self::$plugin_prefix . '_ts_tracker_send_event' ) ) {
wp_schedule_event( time(), 'once_in_week', self::$plugin_prefix . '_ts_tracker_send_event' );
}
}
public static function ts_admin_notices_scripts() {
wp_enqueue_script(
'ts_dismiss_notice',
self::$ts_file_path . '/assets/js/dismiss-notice.js',
'',
'',
false
);
wp_localize_script( 'ts_dismiss_notice', 'ts_dismiss_notice', array (
'ts_prefix_of_plugin' => self::$plugin_prefix,
'ts_admin_url' => admin_url( 'admin-ajax.php' )
) );
}
public static function ts_admin_notices() {
update_option( self::$plugin_prefix . '_allow_tracking', 'dismissed' );
Wcap_TS_Tracker::ts_send_tracking_data( false );
die();
}
private static function ts_tracking_actions() {
if ( isset( $_GET[ self::$plugin_prefix . '_tracker_optin' ] ) && isset( $_GET[ self::$plugin_prefix . '_tracker_nonce' ] ) && wp_verify_nonce( $_GET[ self::$plugin_prefix . '_tracker_nonce' ], self::$plugin_prefix . '_tracker_optin' ) ) {
update_option( self::$plugin_prefix . '_allow_tracking', 'yes' );
Wcap_TS_Tracker::ts_send_tracking_data( true );
header( 'Location: ' . $_SERVER[ 'HTTP_REFERER' ] );
} elseif ( isset( $_GET[ self::$plugin_prefix . '_tracker_optout' ] ) && isset( $_GET[ self::$plugin_prefix . '_tracker_nonce' ] ) && wp_verify_nonce( $_GET[ self::$plugin_prefix . '_tracker_nonce' ], self::$plugin_prefix . '_tracker_optout' ) ) {
update_option( self::$plugin_prefix . '_allow_tracking', 'no' );
Wcap_TS_Tracker::ts_send_tracking_data( false );
header( 'Location: ' . $_SERVER[ 'HTTP_REFERER' ] );
}
}
public static function ts_track_usage_data() {
$admin_url = get_admin_url();
echo '<input type="hidden" id="admin_url" value="' . $admin_url . '"/>';
self::ts_tracking_actions();
if ( 'unknown' === get_option( self::$plugin_prefix . '_allow_tracking', 'unknown' ) ) : ?>
<div class="<?php echo self::$plugin_prefix; ?>-message <?php echo self::$plugin_prefix; ?>-tracker notice notice-info is-dismissible" style="position: relative;">
<div style="position: absolute;"><img class="site-logo" src= " <?php echo self::$ts_file_path . '/assets/images/site-logo-new.jpg '; ?> "></div>
<p style="margin: 10px 0 10px 130px; font-size: medium;">
<?php print( __( 'Want to help make ' . self::$plugin_name . ' even more awesome? Allow ' . self::$plugin_name . ' to collect non-sensitive diagnostic data and usage information and get 20% off on your next purchase. <a href="' . self::$blog_post_link . '">Find out more</a>.', self::$plugin_context ) ); ?></p>
<p class="submit">
<a class="button-primary button button-large" href="<?php echo esc_url( wp_nonce_url( add_query_arg( self::$plugin_prefix . '_tracker_optin', 'true' ), self::$plugin_prefix . '_tracker_optin', self::$plugin_prefix . '_tracker_nonce' ) ); ?>"><?php esc_html_e( 'Allow', self::$plugin_context ); ?></a>
<a class="button-secondary button button-large skip" href="<?php echo esc_url( wp_nonce_url( add_query_arg( self::$plugin_prefix . '_tracker_optout', 'true' ), self::$plugin_prefix . '_tracker_optout', self::$plugin_prefix . '_tracker_nonce' ) ); ?>"><?php esc_html_e( 'No thanks', self::$plugin_context ); ?></a>
</p>
</div>
<?php endif;
}
}