Skip to content

Commit

Permalink
Merge branch 'trunk' into idea/downloaded-themes
Browse files Browse the repository at this point in the history
  • Loading branch information
tommusrhodus committed Jan 9, 2025
2 parents 981a6bd + 63f19ea commit 0342954
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions assets/js/src/components/theme-garden-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const _ThemeGardenList = ( {
fetchThemeById,
activeTheme,
customizeUrl,
search
search,
} ) => {
const [ localThemes, setLocalThemes ] = useState( themes );

Expand Down Expand Up @@ -60,7 +60,7 @@ const _ThemeGardenList = ( {

return (
<div className="tumblr-themes">
{ activeTheme && !search && (
{ activeTheme && ! search && (
<ThemeGardenListItem
theme={ activeTheme }
handleDetailsClick={ handleDetailsClick }
Expand Down
10 changes: 5 additions & 5 deletions assets/js/src/components/theme-garden-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ const selectors = {
/*
We filter out the active theme because <ThemeGardenList /> will insert it at the top of the list.
*/
return DEFAULT_STATE.activeTheme ?
state.themes.filter(
theme => parseInt( theme.id ) !== parseInt( DEFAULT_STATE.activeTheme.id )
) :
state.themes;
return DEFAULT_STATE.activeTheme
? state.themes.filter(
theme => parseInt( theme.id ) !== parseInt( DEFAULT_STATE.activeTheme.id )
)
: state.themes;
},
getIsOverlayOpen( state ) {
return state.isOverlayOpen;
Expand Down
21 changes: 14 additions & 7 deletions src/ThemeGarden.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,20 @@ public function enqueue_admin_styles( $version ): void {
* @return \WP_Error | object
*/
public function get_theme( string $theme_id ) {
$response = wp_remote_get( self::THEME_GARDEN_ENDPOINT . '/theme/' . esc_attr( $theme_id ) . '?time=' . time() );
$status = wp_remote_retrieve_response_code( $response );
$cached_response = get_transient( 'ttgarden_tumblr_theme_response_' . $theme_id );

if ( 200 !== $status ) {
return new \WP_Error();
if ( false === $cached_response ) {
$response = wp_remote_get( self::THEME_GARDEN_ENDPOINT . '/theme/' . esc_attr( $theme_id ) . '?time=' . time() );
$status = wp_remote_retrieve_response_code( $response );
if ( 200 !== $status ) {
return new \WP_Error();
}

$cached_response = wp_remote_retrieve_body( $response );
set_transient( 'ttgarden_tumblr_theme_response_' . $theme_id, $cached_response, DAY_IN_SECONDS );
}

$body = json_decode( wp_remote_retrieve_body( $response ) );
$body = json_decode( wp_remote_retrieve_body( $cached_response ) );

if ( ! isset( $body->response->theme ) ) {
return new \WP_Error();
Expand Down Expand Up @@ -343,12 +349,13 @@ public function maybe_activate_theme(): void {
* @return array
*/
public function get_themes_and_categories(): array {
$cached_response = get_transient( 'ttgarden_tumblr_themes_response' . $this->get_api_query_string() );
$query_string = $this->get_api_query_string();
$cached_response = get_transient( 'ttgarden_tumblr_themes_response_' . $query_string );

if ( false === $cached_response ) {
$response = wp_remote_get( self::THEME_GARDEN_ENDPOINT . $this->get_api_query_string() );
$cached_response = wp_remote_retrieve_body( $response );
set_transient( 'ttgarden_tumblr_themes_response', $cached_response, WEEK_IN_SECONDS );
set_transient( 'ttgarden_tumblr_themes_response_' . $query_string, $cached_response, DAY_IN_SECONDS );
}

$body = json_decode( $cached_response, true );
Expand Down

0 comments on commit 0342954

Please sign in to comment.