Changeset 39296 for trunk/src/wp-includes/rest-api.php
- Timestamp:
- 11/18/2016 07:32:03 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r39278 r39296 870 870 871 871 /** 872 * Determines if a IPv4address is valid.873 * 874 * Does not handleIPv6 addresses.872 * Determines if an IP address is valid. 873 * 874 * Handles both IPv4 and IPv6 addresses. 875 875 * 876 876 * @since 4.7.0 877 877 * 878 * @param string $ip v4 IP 32-bitaddress.879 * @return string|false The valid IP v4address, otherwise false.880 */ 881 function rest_is_ip_address( $ip v4) {882 $ pattern = '/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/';883 884 if ( ! preg_match( $ pattern, $ipv4) ) {878 * @param string $ip IP address. 879 * @return string|false The valid IP address, otherwise false. 880 */ 881 function rest_is_ip_address( $ip ) { 882 $ipv4_pattern = '/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/'; 883 884 if ( ! preg_match( $ipv4_pattern, $ip ) && ! Requests_IPv6::check_ipv6( $ip ) ) { 885 885 return false; 886 886 } 887 887 888 return $ip v4;888 return $ip; 889 889 } 890 890 … … 1054 1054 } 1055 1055 break; 1056 case 'ip v4' :1056 case 'ip' : 1057 1057 if ( ! rest_is_ip_address( $value ) ) { 1058 /* translators: %s: IP address */ 1058 /* translators: %s: IP address */ 1059 1059 return new WP_Error( 'rest_invalid_param', sprintf( __( '%s is not a valid IP address.' ), $value ) ); 1060 1060 } … … 1157 1157 return esc_url_raw( $value ); 1158 1158 1159 case 'ip v4' :1159 case 'ip' : 1160 1160 return sanitize_text_field( $value ); 1161 1161 }
Note: See TracChangeset
for help on using the changeset viewer.