Skip to content
Snippets Groups Projects
Commit 497ef3bf authored by Erick Hitter's avatar Erick Hitter
Browse files

Conditional to confirm we can rewrite

parent 33bba8d0
No related branches found
No related tags found
3 merge requests!6add linting,!5WIP: Add JUnit reporting,!4WIP: Initial release
......@@ -12,6 +12,31 @@ namespace Camo_Image_Proxy;
*
* @return object
*/
function Options() {
function Options() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid, Generic.Functions.OpeningFunctionBraceKernighanRitchie.ContentAfterBrace
return Options::instance();
}
/**
* Can URLs be rewritten to use Camo?
*
* @return bool
*/
function can_rewrite() : bool {
$host = Options()->get( 'host' );
$key = Options()->get( 'key' );
$can_rewrite = true;
// Validate host.
if ( empty( $host ) || ( ! filter_var( $host, FILTER_VALIDATE_URL ) && ! filter_var( $host, FILTER_VALIDATE_IP ) ) ) {
$can_rewrite = false;
}
// Validate key.
// TODO: make sure it's an HMAC or something?
if ( empty( $key ) || ! is_string( $key ) ) {
$can_rewrite = false;
}
return apply_filters( 'camo_image_proxy_can_rewrite', $can_rewrite, $host, $key );
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment