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
Branches
No related tags found
3 merge requests!6add linting,!5WIP: Add JUnit reporting,!4WIP: Initial release
This commit is part of merge request !4. Comments created here will be created in the context of that merge request.
......@@ -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