Skip to content

Instantly share code, notes, and snippets.

@dancameron
Forked from thomasplevy/hsd-patch.php
Last active October 12, 2016 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dancameron/68c4c06f16ff3c364b38a40fd171b9ee to your computer and use it in GitHub Desktop.
Save dancameron/68c4c06f16ff3c364b38a40fd171b9ee to your computer and use it in GitHub Desktop.
<?php
/////////
// API //
/////////
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;
}
$tag_array = array();
$tags = self::get_tags_from_help_scout_by_page( 1, $flush );
if ( empty( $tags->items ) ) {
update_option( self::TAGS_CACHE, $tag_array );
return;
}
for ( $i = 1; $i <= $tags->pages; $i++ ) {
if ( $i === (int) $tags->page ) {
$tag_array = array_merge( $tags->items, $tag_array );
} else {
$paged_tags = self::get_tags_from_help_scout_by_page( $i, $flush );
$tag_array = array_merge( $paged_tags->items, $tag_array );
}
}
update_option( self::TAGS_CACHE, $tag_array );
return $tag_array;
}
public static function get_tags_from_help_scout_by_page( $page_id = 1, $flush = false ) {
$response = HelpScout_API::api_request( 'tags', '?page=' . $page_id, $flush );
return json_decode( $response );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment