1010 * 404 page. This class can be extended to access the 404
1111 * page details such as URL, Time, User Agent etc.
1212 *
13+ * @link https://duckdev.com/products/404-to-301/
14+ * @author Joel James <[email protected] > 15+ * @license http://www.gnu.org/licenses/ GNU General Public License
1316 * @category Core
1417 * @package JJ4T3
1518 * @subpackage 404Data
16- * @author Joel James <[email protected] > 17- * @license http://www.gnu.org/licenses/ GNU General Public License
18- * @link https://duckdev.com/products/404-to-301/
1919 */
2020class JJ4T3_404_Data {
2121
@@ -66,7 +66,6 @@ class JJ4T3_404_Data {
6666 * @access private
6767 */
6868 public function init () {
69-
7069 $ this ->set_ip ();
7170 $ this ->set_ref ();
7271 $ this ->set_ua ();
@@ -80,20 +79,19 @@ public function init() {
8079 * Get real IP address of the user.
8180 * http://stackoverflow.com/a/55790/3845839
8281 *
83- * @param string $ip Default value for IP Address.
84- *
8582 * @since 2.2.6
8683 * @access private
8784 *
85+ * @param string $ip Default value for IP Address.
86+ *
8887 * @return void
8988 */
9089 private function set_ip ( $ ip = '' ) {
91-
92- // IP varibals in priority oder.
93- $ ips = array ( 'HTTP_CLIENT_IP ' , 'HTTP_X_FORWARDED_FOR ' , 'REMOTE_ADDR ' );
94- foreach ( $ ips as $ ip ) {
95- if ( isset ( $ _SERVER [ $ ip ] ) ) {
96- $ ip = $ _SERVER [ $ ip ];
90+ // IP variables in priority oder.
91+ $ headers = array ( 'HTTP_CLIENT_IP ' , 'HTTP_X_FORWARDED_FOR ' , 'REMOTE_ADDR ' );
92+ foreach ( $ headers as $ header ) {
93+ if ( isset ( $ _SERVER [ $ header ] ) ) {
94+ $ ip = $ _SERVER [ $ header ]; // phpcs:ignore
9795 }
9896 }
9997
@@ -102,47 +100,49 @@ private function set_ip( $ip = '' ) {
102100 *
103101 * @since 3.0.0
104102 */
105- $ this ->ip = apply_filters ( 'jj4t3_404_ip ' , $ ip );
103+ $ ip = apply_filters ( 'jj4t3_404_ip ' , $ ip );
104+
105+ $ this ->ip = sanitize_text_field ( $ ip );
106106 }
107107
108108 /**
109109 * Set visitors user agent/browser.
110110 *
111- * @param string $ua Default value for User Agent.
112- *
113111 * @since 3.0.0
114112 * @access private
115113 *
114+ * @param string $ua Default value for User Agent.
115+ *
116116 * @return void
117117 */
118118 private function set_ua ( $ ua = '' ) {
119-
120119 if ( isset ( $ _SERVER ['HTTP_USER_AGENT ' ] ) ) {
121- $ ua = $ _SERVER ['HTTP_USER_AGENT ' ];
120+ $ ua = $ _SERVER ['HTTP_USER_AGENT ' ]; // phpcs:ignore
122121 }
123122
124123 /**
125124 * Filter to alter User Agent.
126125 *
127126 * @since 3.0.0
128127 */
129- $ this ->ua = apply_filters ( 'jj4t3_404_ua ' , $ ua );
128+ $ ua = apply_filters ( 'jj4t3_404_ua ' , $ ua );
129+
130+ $ this ->ua = sanitize_text_field ( $ ua );
130131 }
131132
132133 /**
133134 * Set visitors referring link.
134135 *
135- * @param string $ref Default value for Ref.
136- *
137136 * @since 3.0.0
138137 * @access private
139138 *
139+ * @param string $ref Default value for Ref.
140+ *
140141 * @return void
141142 */
142143 private function set_ref ( $ ref = '' ) {
143-
144144 if ( isset ( $ _SERVER ['HTTP_REFERER ' ] ) ) {
145- $ ref = esc_url ( $ _SERVER ['HTTP_REFERER ' ] );
145+ $ ref = $ _SERVER ['HTTP_REFERER ' ]; // phpcs:ignore
146146 }
147147
148148 /**
@@ -152,23 +152,24 @@ private function set_ref( $ref = '' ) {
152152 *
153153 * @since 3.0.0
154154 */
155- $ this ->ref = apply_filters ( 'jj4t3_404_ref ' , $ ref );
155+ $ ref = apply_filters ( 'jj4t3_404_ref ' , $ ref );
156+
157+ $ this ->ref = esc_url_raw ( $ ref );
156158 }
157159
158160 /**
159161 * Set visitors referring link.
160162 *
161- * @param string $url Default value for 404 URL.
162- *
163163 * @since 3.0.0
164164 * @access private
165165 *
166+ * @param string $url Default value for 404 URL.
167+ *
166168 * @return void
167169 */
168170 private function set_url ( $ url = '' ) {
169-
170171 if ( isset ( $ _SERVER ['REQUEST_URI ' ] ) ) {
171- $ url = untrailingslashit ( esc_url ( $ _SERVER ['REQUEST_URI ' ] ) );
172+ $ url = $ _SERVER ['REQUEST_URI ' ]; // phpcs:ignore
172173 }
173174
174175 /**
@@ -178,7 +179,9 @@ private function set_url( $url = '' ) {
178179 *
179180 * @since 3.0.0
180181 */
181- $ this ->url = apply_filters ( 'jj4t3_404_url ' , $ url );
182+ $ url = apply_filters ( 'jj4t3_404_url ' , $ url );
183+
184+ $ this ->url = untrailingslashit ( esc_url_raw ( $ url ) );
182185 }
183186
184187 /**
@@ -190,11 +193,10 @@ private function set_url( $url = '' ) {
190193 * @return void
191194 */
192195 private function set_time () {
193-
194196 /**
195197 * Filter to alter current time.
196198 *
197- * @note If you using this filter, remember to
199+ * @note If you using this filter, remember to
198200 * return proper MySQL time format.
199201 *
200202 * @since 3.0.0
@@ -215,7 +217,6 @@ private function set_time() {
215217 * @return boolean
216218 */
217219 public function is_excluded () {
218-
219220 $ excluded = jj4t3_get_option ( 'exclude_paths ' , '' );
220221
221222 $ paths = array ();
@@ -229,7 +230,7 @@ public function is_excluded() {
229230 /**
230231 * Filter to alter exclude path values.
231232 *
232- * @note You should return array if strings .
233+ * @note You should return array if strings .
233234 *
234235 * @since 3.0.0
235236 */
@@ -249,5 +250,4 @@ public function is_excluded() {
249250
250251 return false ;
251252 }
252-
253253}
0 commit comments