Add a check to make themes API query safer (#51081)
* Add check to ensure themes API is safe * Changelog * Lint * Add more checks for malformed data
This commit is contained in:
parent
0be7e3deb0
commit
4680b3dcfb
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: fix
|
||||||
|
|
||||||
|
Add check to ensure themes API is safe
|
|
@ -78,10 +78,10 @@ class OnboardingThemes {
|
||||||
usort(
|
usort(
|
||||||
$themes,
|
$themes,
|
||||||
function ( $product_1, $product_2 ) {
|
function ( $product_1, $product_2 ) {
|
||||||
if ( ! property_exists( $product_1, 'id' ) || ! property_exists( $product_1, 'slug' ) ) {
|
if ( ! is_object( $product_1 ) || ! property_exists( $product_1, 'id' ) || ! property_exists( $product_1, 'slug' ) ) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if ( ! property_exists( $product_2, 'id' ) || ! property_exists( $product_2, 'slug' ) ) {
|
if ( ! is_object( $product_2 ) || ! property_exists( $product_2, 'id' ) || ! property_exists( $product_2, 'slug' ) ) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if ( in_array( 'Storefront', array( $product_1->slug, $product_2->slug ), true ) ) {
|
if ( in_array( 'Storefront', array( $product_1->slug, $product_2->slug ), true ) ) {
|
||||||
|
@ -110,16 +110,22 @@ class OnboardingThemes {
|
||||||
$themes = array();
|
$themes = array();
|
||||||
|
|
||||||
if ( ! is_wp_error( $theme_data ) ) {
|
if ( ! is_wp_error( $theme_data ) ) {
|
||||||
$theme_data = json_decode( $theme_data['body'] );
|
$theme_data = json_decode( $theme_data['body'] );
|
||||||
$woo_themes = property_exists( $theme_data, 'products' ) ? $theme_data->products : array();
|
|
||||||
$sorted_themes = self::sort_woocommerce_themes( $woo_themes );
|
|
||||||
|
|
||||||
foreach ( $sorted_themes as $theme ) {
|
if ( $theme_data ) {
|
||||||
$slug = sanitize_title_with_dashes( $theme->slug );
|
$woo_themes = property_exists( $theme_data, 'products' ) ? $theme_data->products : array();
|
||||||
$themes[ $slug ] = (array) $theme;
|
$sorted_themes = self::sort_woocommerce_themes( $woo_themes );
|
||||||
$themes[ $slug ]['is_installed'] = false;
|
|
||||||
$themes[ $slug ]['has_woocommerce_support'] = true;
|
foreach ( $sorted_themes as $theme ) {
|
||||||
$themes[ $slug ]['slug'] = $slug;
|
if ( ! isset( $theme->slug ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$slug = sanitize_title_with_dashes( $theme->slug );
|
||||||
|
$themes[ $slug ] = (array) $theme;
|
||||||
|
$themes[ $slug ]['is_installed'] = false;
|
||||||
|
$themes[ $slug ]['has_woocommerce_support'] = true;
|
||||||
|
$themes[ $slug ]['slug'] = $slug;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue