Skip to content

Instantly share code, notes, and snippets.

@thomasplevy
Created November 14, 2017 23:34
Show Gist options
  • Save thomasplevy/2086ae987441ed2ec39a301437813d55 to your computer and use it in GitHub Desktop.
Save thomasplevy/2086ae987441ed2ec39a301437813d55 to your computer and use it in GitHub Desktop.
<?php
add_filter( 'hsd_get_user_customer_ids', 'check_hsd_customer_id', 999, 2 );
check_hsd_customer_id( $hsd_ids, $user_id ) {
if ( $hsd_ids ) {
$now = current_time( 'timestamp' );
$last_sync = get_user_meta( $user_id, 'pp_hsd_last_sync', true );
if ( ! $last_sync || $last_sync <= ( $now - ( HOUR_IN_SECONDS * 6 ) ) ) {
update_user_meta( $user_id, 'pp_hsd_last_sync', $now );
foreach ( $hsd_ids as $i => $id ) {
$req = HelpScout_API::api_request( 'customers/' . $id );
$res = json_decode( $req );
if ( $res && isset( $res->code ) && 404 === $res->code ) {
unset( $hsd_ids[ $i ] );
}
}
}
}
return $hsd_ids;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment