| 1 |
<?php |
| 2 |
|
| 3 |
defined('ABSPATH') or die("Jog on!"); |
| 4 |
|
| 5 |
/** |
| 6 |
* Get a user's ID |
| 7 |
* |
| 8 |
* Class SV_SC_USER_IP |
| 9 |
*/ |
| 10 |
class SV_SC_USER_IP extends SV_Preset { |
| 11 |
|
| 12 |
protected function unsanitised() { |
| 13 |
|
| 14 |
// Code based on WP Beginner article: http://www.wpbeginner.com/wp-tutorials/how-to-display-a-users-ip-address-in-wordpress/ |
| 15 |
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { |
| 16 |
$ip = $_SERVER['HTTP_CLIENT_IP']; |
| 17 |
} |
| 18 |
elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
| 19 |
$ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
| 20 |
} |
| 21 |
else { |
| 22 |
$ip = $_SERVER['REMOTE_ADDR']; |
| 23 |
} |
| 24 |
return $ip; |
| 25 |
|
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Today's date |
| 31 |
* |
| 32 |
* Class SV_SC_TODAYS_DATE |
| 33 |
*/ |
| 34 |
class SV_SC_TODAYS_DATE extends SV_Preset { |
| 35 |
|
| 36 |
protected function unsanitised() { |
| 37 |
|
| 38 |
$args = $this->get_arguments(); |
| 39 |
|
| 40 |
$date_format = ( false === empty( $args['format'] ) ) ? $args['format'] : 'd/m/Y'; |
| 41 |
|
| 42 |
return date( $date_format ); |
| 43 |
|
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* User Agent |
| 49 |
* |
| 50 |
* Class SV_SC_USER_AGENT |
| 51 |
*/ |
| 52 |
class SV_SC_USER_AGENT extends SV_Preset { |
| 53 |
protected function unsanitised() { |
| 54 |
return $_SERVER['HTTP_USER_AGENT']; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Page title |
| 60 |
* |
| 61 |
* Class SV_SC_PAGE_TITLE |
| 62 |
*/ |
| 63 |
class SV_SC_PAGE_TITLE extends SV_Preset { |
| 64 |
|
| 65 |
protected function unsanitised() { |
| 66 |
return the_title('', '', false); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Login Page |
| 72 |
* |
| 73 |
* Class SV_SC_LOGIN_PAGE |
| 74 |
*/ |
| 75 |
class SV_SC_LOGIN_PAGE extends SV_Preset { |
| 76 |
|
| 77 |
public function init() { |
| 78 |
$this->escape_method = 'esc_url_raw'; |
| 79 |
} |
| 80 |
|
| 81 |
protected function unsanitised() { |
| 82 |
|
| 83 |
$args = $this->get_arguments(); |
| 84 |
|
| 85 |
$redirect = ( false === empty( $args['redirect'] ) ) ? $args['redirect'] : ''; |
| 86 |
|
| 87 |
return wp_login_url( $redirect ); |
| 88 |
} |
| 89 |
} |
| 90 |
/** |
| 91 |
* Policy URL |
| 92 |
* |
| 93 |
* Class SV_SC_POLICY_URL |
| 94 |
*/ |
| 95 |
class SV_SC_POLICY_URL extends SV_Preset { |
| 96 |
|
| 97 |
public function init() { |
| 98 |
$this->escape_method = 'esc_url_raw'; |
| 99 |
} |
| 100 |
|
| 101 |
protected function unsanitised() { |
| 102 |
return get_privacy_policy_url(); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* User Info |
| 108 |
* |
| 109 |
* Class SV_USER_INFO |
| 110 |
*/ |
| 111 |
class SV_SC_USER_INFO extends SV_Preset { |
| 112 |
|
| 113 |
protected function unsanitised() { |
| 114 |
|
| 115 |
$args = $this->get_arguments(); |
| 116 |
|
| 117 |
$key = ( false === empty( $args['_sh_cd_func'] ) ) ? $args['_sh_cd_func'] : 'ID'; |
| 118 |
|
| 119 |
$current_user = wp_get_current_user(); |
| 120 |
|
| 121 |
// Not logged in? |
| 122 |
if ( false === $current_user->exists() ) { |
| 123 |
return ''; |
| 124 |
} |
| 125 |
|
| 126 |
switch ( $key ) { |
| 127 |
|
| 128 |
case 'user_login': |
| 129 |
return $current_user->user_login; |
| 130 |
break; |
| 131 |
case 'user_email': |
| 132 |
return $current_user->user_email; |
| 133 |
break; |
| 134 |
case 'user_firstname': |
| 135 |
return $current_user->user_firstname; |
| 136 |
break; |
| 137 |
case 'user_lastname': |
| 138 |
return $current_user->user_lastname; |
| 139 |
break; |
| 140 |
case 'display_name': |
| 141 |
return $current_user->display_name; |
| 142 |
break; |
| 143 |
default: |
| 144 |
return $current_user->ID; |
| 145 |
|
| 146 |
} |
| 147 |
|
| 148 |
return ''; |
| 149 |
} |
| 150 |
} |
| 151 |
|