array(), 'updated' => time(), ) ); $data['updated'] = time(); $url = 'https://woocommerce.com/wp-json/wccom/marketplace-suggestions/1.0/suggestions.json'; $request = wp_safe_remote_get( $url ); if ( is_wp_error( $request ) ) { self::retry(); return update_option( 'woocommerce_marketplace_suggestions', $data, false ); } $body = wp_remote_retrieve_body( $request ); if ( empty( $body ) ) { self::retry(); return update_option( 'woocommerce_marketplace_suggestions', $data, false ); } $body = json_decode( $body, true ); if ( empty( $body ) || ! is_array( $body ) ) { self::retry(); return update_option( 'woocommerce_marketplace_suggestions', $data, false ); } $data['suggestions'] = $body; return update_option( 'woocommerce_marketplace_suggestions', $data, false ); } /** * Used when an error has occured when fetching suggestions. * Re-schedules the job earlier than the main weekly one. */ public static function retry() { WC()->queue()->cancel_all( 'woocommerce_update_marketplace_suggestions' ); WC()->queue()->schedule_single( time() + DAY_IN_SECONDS, 'woocommerce_update_marketplace_suggestions' ); } } WC_Marketplace_Updater::load();