← All changes
|
modules/atomic-widgets/props-resolver/transformers/svg-src-transformer.php
+23
-9
4.2.0-dev2
→
4.3.1
View file →
| @@ -48,25 +48,39 @@ | ||
| 48 | 48 | if ( ! $url ) { |
| 49 | 49 | return null; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | + $local_content = $this->fetch_local_svg_content( $url ); | |
| 53 | + | |
| 54 | + return $local_content ? $local_content : $this->fetch_remote_svg_content( $url ); | |
| 55 | + } | |
| 56 | + | |
| 57 | + private function fetch_local_svg_content( string $url ): ?string { | |
| 52 | 58 | $local_path = $this->resolve_local_path( $url ); |
| 53 | 59 | |
| 54 | - if ( $local_path ) { | |
| 55 | - $content = Utils::file_get_contents( $local_path ); | |
| 60 | + if ( ! $local_path ) { | |
| 61 | + return null; | |
| 62 | + } | |
| 56 | 63 | |
| 57 | - if ( $content ) { | |
| 58 | - return $content; | |
| 59 | - } | |
| 60 | - } | |
| 64 | + $content = Utils::file_get_contents( $local_path ); | |
| 61 | 65 | |
| 66 | + return $content ? $content : null; | |
| 67 | + } | |
| 68 | + | |
| 69 | + private function fetch_remote_svg_content( string $url ): ?string { | |
| 62 | 70 | $response = wp_safe_remote_get( $url ); |
| 63 | 71 | |
| 64 | - if ( ! is_wp_error( $response ) ) { | |
| 65 | - return $response['body']; | |
| 72 | + if ( is_wp_error( $response ) ) { | |
| 73 | + return null; | |
| 66 | 74 | } |
| 67 | 75 | |
| 68 | - return null; | |
| 76 | + if ( \WP_Http::OK !== (int) wp_remote_retrieve_response_code( $response ) ) { | |
| 77 | + return null; | |
| 78 | + } | |
| 79 | + | |
| 80 | + $body = wp_remote_retrieve_body( $response ); | |
| 81 | + | |
| 82 | + return $body ? $body : null; | |
| 69 | 83 | } |
| 70 | 84 | |
| 71 | 85 | private function resolve_local_path( string $url ): ?string { |
| 72 | 86 | $site_url = site_url(); |