session_referrer_cookie_name() ] ) ) { $url = ''; if ( isset( $_SERVER['HTTP_REFERER'] ) && ! empty( $_SERVER['HTTP_REFERER'] ) ) { $url = sanitize_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ); } $this->process_referrer_url( $url ); } } /** * Receive the referrer from front-end js. * * @return void */ public function handle_js_session_referrer( $referrer ) { $this->process_referrer_url( $referrer, false ); } /** * Process the referring url and optionally save it to a cookie. * * @return void */ private function process_referrer_url( $url, $set_cookie = true ) { if ( function_exists( 'wp_doing_cron' ) && wp_doing_cron() ) { return; } if ( headers_sent() ) { return; } if ( $url !== '' ) { $url = sanitize_url( $url ); } $cookie_name = $this->session_referrer_cookie_name(); if ( $set_cookie ) { setcookie( $cookie_name, $url, 0, '/' ); } $_COOKIE[ $cookie_name ] = $url; } /** * Return the session referrer if one exists. * * @return string */ public function get_session_referrer_url() { $cookie_name = $this->session_referrer_cookie_name(); return ( isset( $_COOKIE[ $cookie_name ] ) ) ? wp_strip_all_tags( wp_unslash( $_COOKIE[ $cookie_name ] ) ) : ''; } /** * Get the visitor cookie with browser information. * * @return array */ public function get_visitor_cookie() { $cookie_name = $this->visitor_cookie_name(); return ( isset( $_COOKIE[ $cookie_name ] ) ) ? json_decode( wp_strip_all_tags( wp_unslash( $_COOKIE[ $cookie_name ] ) ), true ) : array(); } }