Small fixes for PR woocommerce/woocommerce-admin#2503
- Use get_instance function instead of constructor - Update URL to be HTTPS - Add error checking for failed remote gets
This commit is contained in:
parent
ab7ceeed23
commit
ac28e781c7
|
@ -118,10 +118,12 @@ class WC_Admin_Onboarding {
|
||||||
$themes_transient_name = 'wc_onboarding_themes';
|
$themes_transient_name = 'wc_onboarding_themes';
|
||||||
$themes = get_transient( $themes_transient_name );
|
$themes = get_transient( $themes_transient_name );
|
||||||
if ( false === $themes ) {
|
if ( false === $themes ) {
|
||||||
$theme_data = wp_remote_get( 'http://woocommerce.com/wp-json/wccom-extensions/1.0/search?category=themes' );
|
$theme_data = wp_remote_get( 'https://woocommerce.com/wp-json/wccom-extensions/1.0/search?category=themes' );
|
||||||
$theme_data = json_decode( $theme_data['body'] );
|
|
||||||
$themes = array();
|
$themes = array();
|
||||||
|
|
||||||
|
if ( ! is_wp_error( $theme_data ) ) {
|
||||||
|
$theme_data = json_decode( $theme_data['body'] );
|
||||||
|
|
||||||
foreach ( $theme_data->products as $theme ) {
|
foreach ( $theme_data->products as $theme ) {
|
||||||
$slug = sanitize_title( $theme->slug );
|
$slug = sanitize_title( $theme->slug );
|
||||||
$themes[ $slug ] = (array) $theme;
|
$themes[ $slug ] = (array) $theme;
|
||||||
|
@ -144,6 +146,7 @@ class WC_Admin_Onboarding {
|
||||||
|
|
||||||
set_transient( $themes_transient_name, $themes, DAY_IN_SECONDS );
|
set_transient( $themes_transient_name, $themes, DAY_IN_SECONDS );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$themes = apply_filters( 'woocommerce_admin_onboarding_themes', $themes );
|
$themes = apply_filters( 'woocommerce_admin_onboarding_themes', $themes );
|
||||||
return array_values( $themes );
|
return array_values( $themes );
|
||||||
|
@ -181,8 +184,13 @@ class WC_Admin_Onboarding {
|
||||||
$woocommerce_products = get_transient( $product_data_transient_name );
|
$woocommerce_products = get_transient( $product_data_transient_name );
|
||||||
if ( false === $woocommerce_products ) {
|
if ( false === $woocommerce_products ) {
|
||||||
$woocommerce_products = wp_remote_get( 'https://woocommerce.com/wp-json/wccom-extensions/1.0/search?category=product-type' );
|
$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 );
|
set_transient( $product_data_transient_name, $woocommerce_products, DAY_IN_SECONDS );
|
||||||
}
|
}
|
||||||
|
|
||||||
$product_data = json_decode( $woocommerce_products['body'] );
|
$product_data = json_decode( $woocommerce_products['body'] );
|
||||||
$products = array();
|
$products = array();
|
||||||
|
|
||||||
|
@ -242,4 +250,4 @@ class WC_Admin_Onboarding {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new WC_Admin_Onboarding();
|
WC_Admin_Onboarding::get_instance();
|
||||||
|
|
Loading…
Reference in New Issue