Merge pull request woocommerce/woocommerce-admin#2543 from woocommerce/2503-followup
Add error checking for failed remote gets added in woocommerce/woocommerce-admin#2503
This commit is contained in:
commit
ca40be6676
|
@ -118,10 +118,12 @@ class WC_Admin_Onboarding {
|
|||
$themes_transient_name = 'wc_onboarding_themes';
|
||||
$themes = get_transient( $themes_transient_name );
|
||||
if ( false === $themes ) {
|
||||
$theme_data = wp_remote_get( 'http://woocommerce.com/wp-json/wccom-extensions/1.0/search?category=themes' );
|
||||
$theme_data = json_decode( $theme_data['body'] );
|
||||
$theme_data = wp_remote_get( 'https://woocommerce.com/wp-json/wccom-extensions/1.0/search?category=themes' );
|
||||
$themes = array();
|
||||
|
||||
if ( ! is_wp_error( $theme_data ) ) {
|
||||
$theme_data = json_decode( $theme_data['body'] );
|
||||
|
||||
foreach ( $theme_data->products as $theme ) {
|
||||
$slug = sanitize_title( $theme->slug );
|
||||
$themes[ $slug ] = (array) $theme;
|
||||
|
@ -144,6 +146,7 @@ class WC_Admin_Onboarding {
|
|||
|
||||
set_transient( $themes_transient_name, $themes, DAY_IN_SECONDS );
|
||||
}
|
||||
}
|
||||
|
||||
$themes = apply_filters( 'woocommerce_admin_onboarding_themes', $themes );
|
||||
return array_values( $themes );
|
||||
|
@ -181,8 +184,13 @@ class WC_Admin_Onboarding {
|
|||
$woocommerce_products = get_transient( $product_data_transient_name );
|
||||
if ( false === $woocommerce_products ) {
|
||||
$woocommerce_products = wp_remote_get( 'https://woocommerce.com/wp-json/wccom-extensions/1.0/search?category=product-type' );
|
||||
if ( is_wp_error( $woocommerce_products ) ) {
|
||||
return $product_types;
|
||||
}
|
||||
|
||||
set_transient( $product_data_transient_name, $woocommerce_products, DAY_IN_SECONDS );
|
||||
}
|
||||
|
||||
$product_data = json_decode( $woocommerce_products['body'] );
|
||||
$products = array();
|
||||
|
||||
|
@ -242,4 +250,4 @@ class WC_Admin_Onboarding {
|
|||
}
|
||||
}
|
||||
|
||||
new WC_Admin_Onboarding();
|
||||
WC_Admin_Onboarding::get_instance();
|
||||
|
|
Loading…
Reference in New Issue