PluginProbe
Elementor Website Builder – more than just a page builder / 3.6.0-dev1
Elementor Website Builder – more than just a page builder v3.6.0-dev1
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / trunk / core / utils / http.php

http.php in Elementor Website Builder – more than just a page builder 3.6.0-dev1, at trunk/core/utils/http.php

51 lines 981 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Utils;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 class Http extends \WP_Http {
9 /**
10 * Pass multiple urls to implements a fallback machine when one of the urls
11 * is sending an error or not exists anymore.
12 *
13 * @param array $urls
14 * @param array $args
15 *
16 * @return array|\WP_Error|null
17 */
18 public function request_with_fallback( array $urls, $args = [] ) {
19 $response = null;
20
21 foreach ( $urls as $url ) {
22 $response = $this->request( $url, $args );
23
24 if ( $this->is_successful_response( $response ) ) {
25 return $response;
26 }
27 }
28
29 return $response;
30 }
31
32 /**
33 * @param $response
34 *
35 * @return bool
36 */
37 private function is_successful_response( $response ) {
38 if ( is_wp_error( $response ) ) {
39 return false;
40 }
41
42 $response_code = (int) wp_remote_retrieve_response_code( $response );
43
44 if ( in_array( $response_code, [ 0, 404, 500 ], true ) ) {
45 return false;
46 }
47
48 return true;
49 }
50 }
51