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