-
-
Save dancameron/68c4c06f16ff3c364b38a40fd171b9ee to your computer and use it in GitHub Desktop.
This file contains 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 | |
///////// | |
// 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