Created
November 14, 2017 23:34
-
-
Save thomasplevy/2086ae987441ed2ec39a301437813d55 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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