# assistant/1.4.7/backend/src/Hooks/ImageProxy.php

Assistant – Every Day Productivity Apps, version 1.4.7. 52 lines.

- Page: https://pluginprobe.com/plugins/assistant/1.4.7/code/backend/src/Hooks/ImageProxy.php
- Raw: https://pluginprobe.com/plugins/assistant/1.4.7/raw/backend/src/Hooks/ImageProxy.php
- Modified: 2023-12-08T15:40:32+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/assistant/1.4.7/code/backend/src/Hooks/ImageProxy.php#L10-L20`.

```php
<?php

namespace FL\Assistant\Hooks;

class ImageProxy {

	public function __construct() {
		add_action(
			'init', function() {
				if ( ! current_user_can( 'edit_others_posts' ) ) {
					return;
				}
				if ( isset( $_GET['fl_asst_image_proxy'] ) ) {
					self::render_image();
				}
			}
		);
	}

	public function render_image() {
		if ( ! isset(  $_GET['fl_asst_image_proxy'] ) && ! isset( $_GET['url'] ) ) {
			return;
		}

		$url = esc_url_raw( $_GET['url'] );
		$url = urldecode( $url );

		if ( 0 !== strpos( $url, 'http' ) ) {
			return;
		}

		$response = wp_safe_remote_get( $url );

		if ( is_wp_error( $response ) ) {
			return;
		}

		$body = wp_remote_retrieve_body( $response );
		$headers = wp_remote_retrieve_headers( $response );

		if ( ! isset( $headers['content-type'] ) ) {
			return;
		} elseif ( 0 !== strpos( $headers['content-type'], 'image/' ) ) {
			return;
		}

		header( 'Content-type: ' . $headers['content-type'] );
		echo $body;
		die();
	}
}

```
