array( 'header' => array( "Content-type: application/json", "X-API-KEY: $avsecure_apikey"), 'method' => 'GET' ) ); $context = stream_context_create( $options ); try { $content = @file_get_contents( $url, false, $context ); if ( $content === "" ) { return false; } $region = json_decode( $content ); if ( $region->{'region'} !== "GB" ) { return true; } } catch ( Exception $e ) {} return false; } // avsecure_user_authenticated returns true if user has valid token passed as query parameters function avsecure_user_authenticated( $params, $ip, $origin ) { global $avsecure_network, $avsecure_apikey; if ( !is_array( $params ) || $params['uuid'] == "" ) { if ( $ip === 'UNKNOWN' ) { return false; } return avsecure_check_ip( $ip ); } $js_string = json_encode( array( 'message' => $params['uuid'] ) ); // use key 'http' even if you send the request to https://... $options = array( 'http' => array( 'header' => array( "Content-type: application/json", "X-API-KEY: $avsecure_apikey", "Origin: $origin"), 'method' => 'POST', 'content' => $js_string ) ); $url = "https://api.avsecure.$avsecure_network/verifier/v1/verify"; $context = stream_context_create( $options ); try { $content = @file_get_contents( $url, false, $context ); if ( $content !== false ) { return true; } } catch ( Exception $e ) {} return false; } function avsecure_home_url_link_filter( $url, $path, $orig_scheme, $blog_id ) { if ( isset( $_GET['uuid'] ) && !empty( $_GET['uuid'] ) ) { if ( strstr( $url, "?" ) ) { $url .= "&"; } else { $url .= "?"; } $url .= 'uuid=' . $_GET['uuid']; } return untrailingslashit( $url ); } add_filter( 'home_url', 'avsecure_home_url_link_filter', 13, 4 ); function avsecure_page_link_filter( $link, $post_id, $sample ){ return untrailingslashit( $link ); } add_filter( 'page_link', 'avsecure_page_link_filter', 10, 3 ); function avsecure_post_link_filter( $url, $post, $leavename=false ) { return untrailingslashit( $url ); } add_filter( 'post_link', 'avsecure_post_link_filter', 12, 3 ); if ( $GLOBALS['pagenow'] !== 'wp-login.php' ) { if ( !is_admin() ) { $uri = $_SERVER['REQUEST_URI']; $query_params = avsecure_get_query_parameters( $uri ); $ip = avsecure_get_client_ip_server(); $origin = avsecure_get_client_origin(); if ( ( avsecure_user_authenticated( $query_params, $ip, $origin) === FALSE ) ) { header( "Location: ". get_redirect_url() ); die(); } } } function get_current_url() { $proto_https = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on'; $forwarded_https = isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'; $proto = $proto_https || $forwarded_https ? 'https' : 'http'; return "$proto://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; } function get_custom_login_parameters() { global $avsecure_custom_login_background; if (empty($avsecure_custom_login_background)) { return ''; } return '&cpBgUrl=' . urlencode($avsecure_custom_login_background); } // get_redirect_url generates url for redirection function get_redirect_url() { global $avsecure_network; $redirect_url = "https://agepass.$avsecure_network/age_wall.html"; return $redirect_url . "?url=" . urlencode(get_current_url()) . get_custom_login_parameters(); }