Skip to content

Instantly share code, notes, and snippets.

@thomasplevy
Created October 11, 2016 21:21
Show Gist options
  • Save thomasplevy/90ce8013c5be50cfff65b7f7fb0fc493 to your computer and use it in GitHub Desktop.
Save thomasplevy/90ce8013c5be50cfff65b7f7fb0fc493 to your computer and use it in GitHub Desktop.
<?php
public static function get_tags_from_help_scout( $flush = false ) {
$tag_cache = get_option( self::TAGS_CACHE, false );
if ( $tag_cache && ! $flush ) {
return $tag_cache;
}
$page = 1;
$tags = array();
while ( true ) {
$r = self::get_tags_from_help_scout_by_page( $page, $flush );
if ( $r->items ) {
$tags = array_merge( $tags, $r->items );
}
if ( $r->page === $r->pages ) {
break;
} else {
$page++;
}
}
update_option( self::TAGS_CACHE, $tags );
return $tags;
}
private static function get_tags_from_help_scout_by_page( $page = 1, $flush = false ) {
$response = HelpScout_API::api_request( 'tags', '?page=' . $page, $flush );
error_log( 'response: ' . print_r( $response, true ) );
return json_decode( $response );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment