| @@ -126,8 +126,11 @@ | ||
| 126 | 126 | #-------------------------------------------------------------------------------- |
| 127 | 127 | |
| 128 | 128 | if ( ! function_exists( 'fs_request_get' ) ) { |
| 129 | 129 | /** |
| 130 | + * A helper method to fetch GET/POST user input with an optional default value when the input is not set. | |
| 131 | + * @author Vova Feldman (@svovaf) | |
| 132 | + * | |
| 130 | 133 | * @param string $key |
| 131 | 134 | * @param mixed $def |
| 132 | 135 | * @param string|bool $type Since 1.2.1.7 - when set to 'get' will look for the value passed via querystring, when |
| 133 | 136 | * set to 'post' will look for the value passed via the POST request's body, otherwise, |
| @@ -139,8 +142,12 @@ | ||
| 139 | 142 | if ( is_string( $type ) ) { |
| 140 | 143 | $type = strtolower( $type ); |
| 141 | 144 | } |
| 142 | 145 | |
| 146 | + /** | |
| 147 | + * Note to WordPress.org Reviewers: | |
| 148 | + * This is a helper method to fetch GET/POST user input with an optional default value when the input is not set. The actual sanitization is done in the scope of the function's usage. | |
| 149 | + */ | |
| 143 | 150 | switch ( $type ) { |
| 144 | 151 | case 'post': |
| 145 | 152 | $value = isset( $_POST[ $key ] ) ? $_POST[ $key ] : $def; |
| 146 | 153 | break; |
| @@ -162,19 +169,41 @@ | ||
| 162 | 169 | } |
| 163 | 170 | } |
| 164 | 171 | |
| 165 | 172 | if ( ! function_exists( 'fs_request_get_bool' ) ) { |
| 173 | + /** | |
| 174 | + * A helper method to fetch GET/POST user boolean input with an optional default value when the input is not set. | |
| 175 | + * | |
| 176 | + * @author Vova Feldman (@svovaf) | |
| 177 | + * | |
| 178 | + * @param string $key | |
| 179 | + * @param bool $def | |
| 180 | + * | |
| 181 | + * @return bool|mixed | |
| 182 | + */ | |
| 166 | 183 | function fs_request_get_bool( $key, $def = false ) { |
| 167 | - if ( ! isset( $_REQUEST[ $key ] ) ) { | |
| 184 | + $val = fs_request_get( $key, null ); | |
| 185 | + | |
| 186 | + if ( is_null( $val ) ) { | |
| 168 | 187 | return $def; |
| 169 | 188 | } |
| 170 | 189 | |
| 171 | - if ( 1 == $_REQUEST[ $key ] || 'true' === strtolower( $_REQUEST[ $key ] ) ) { | |
| 172 | - return true; | |
| 173 | - } | |
| 190 | + if ( is_bool( $val ) ) { | |
| 191 | + return $val; | |
| 192 | + } else if ( is_numeric( $val ) ) { | |
| 193 | + if ( 1 == $val ) { | |
| 194 | + return true; | |
| 195 | + } else if ( 0 == $val ) { | |
| 196 | + return false; | |
| 197 | + } | |
| 198 | + } else if ( is_string( $val ) ) { | |
| 199 | + $val = strtolower( $val ); | |
| 174 | 200 | |
| 175 | - if ( 0 == $_REQUEST[ $key ] || 'false' === strtolower( $_REQUEST[ $key ] ) ) { | |
| 176 | - return false; | |
| 201 | + if ( 'true' === $val ) { | |
| 202 | + return true; | |
| 203 | + } else if ( 'false' === $val ) { | |
| 204 | + return false; | |
| 205 | + } | |
| 177 | 206 | } |
| 178 | 207 | |
| 179 | 208 | return $def; |
| 180 | 209 | } |