add_action('init', 'redirect_resources_check'); function redirect_resources_check() { $request_uri = filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL); $segments = explode('/', trim($request_uri, '/')); // Handling the resources URL logic if (in_array('resources', $segments)) { // Check if the current page is a resource-type post $resource_type = get_query_var('resource-type'); if ($resource_type) { // Redirect only if the resource-type page is directly accessed if(count($segments) > 1 && $segments[1] == 'resource-type') { // Redirect to the resources page $resources_page_url = home_url('/resources/'); wp_redirect($resources_page_url); exit; } } if (!is_user_logged_in() && !current_user_can('administrator')) { if (!isset($_COOKIE['freeaccess']) || $_COOKIE['freeaccess'] !== 'true') { $resource_url = "https://" . $_SERVER['HTTP_HOST'] . $request_uri; setcookie('resourcedownload', $resource_url, time() + (30 * 24 * 60 * 60), "/"); wp_redirect('https://ethisphere.com/access-free-resources/'); exit; } } } $getvariable = filter_input(INPUT_GET, 'freersaccess', FILTER_SANITIZE_URL); // If user is on the "thank-you" page if ($getvariable == 'true') { // Set the "freeaccess" cookie to "true" setcookie('freeaccess', 'true', time() + (30 * 24 * 60 * 60), "/"); // Use WordPress's filter_input to retrieve the cookie value $resourcedownload = filter_input(INPUT_COOKIE, 'resourcedownload', FILTER_SANITIZE_URL); // Clear the cookie by setting its expiration to a past date setcookie('resourcedownload', '', time() - 3600, "/"); // Redirect the user back to the saved URL wp_redirect($resourcedownload); exit; } } Uncategorized Archives - Ethisphere | Good. Smart. Business. Profit.® Skip to content

Uncategorized

Showing all 3 results