diff --git a/wp-includes/rest-api.php b/wp-includes/rest-api.php index 741e76837f..ffc691916f 100644 --- a/wp-includes/rest-api.php +++ b/wp-includes/rest-api.php @@ -869,23 +869,23 @@ function rest_parse_request_arg( $value, $request, $param ) { } /** - * Determines if a IPv4 address is valid. + * Determines if an IP address is valid. * - * Does not handle IPv6 addresses. + * Handles both IPv4 and IPv6 addresses. * * @since 4.7.0 * - * @param string $ipv4 IP 32-bit address. - * @return string|false The valid IPv4 address, otherwise false. + * @param string $ip IP address. + * @return string|false The valid IP address, otherwise false. */ -function rest_is_ip_address( $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]?)$/'; +function rest_is_ip_address( $ip ) { + $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]?)$/'; - if ( ! preg_match( $pattern, $ipv4 ) ) { + if ( ! preg_match( $ipv4_pattern, $ip ) && ! Requests_IPv6::check_ipv6( $ip ) ) { return false; } - return $ipv4; + return $ip; } /** @@ -1053,9 +1053,9 @@ function rest_validate_value_from_schema( $value, $args, $param = '' ) { return new WP_Error( 'rest_invalid_email', __( 'Invalid email address.' ) ); } break; - case 'ipv4' : + case 'ip' : if ( ! rest_is_ip_address( $value ) ) { - /* translators: %s: IP address */ + /* translators: %s: IP address */ return new WP_Error( 'rest_invalid_param', sprintf( __( '%s is not a valid IP address.' ), $value ) ); } break; @@ -1156,7 +1156,7 @@ function rest_sanitize_value_from_schema( $value, $args ) { case 'uri' : return esc_url_raw( $value ); - case 'ipv4' : + case 'ip' : return sanitize_text_field( $value ); } } diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index bfa3159bf1..09223c06b9 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php @@ -1115,7 +1115,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { 'author_ip' => array( 'description' => __( 'IP address for the object author.' ), 'type' => 'string', - 'format' => 'ipv4', + 'format' => 'ip', 'context' => array( 'edit' ), 'default' => '127.0.0.1', ), diff --git a/wp-includes/version.php b/wp-includes/version.php index ec63ca0885..ea82272c88 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-beta4-39295'; +$wp_version = '4.7-beta4-39296'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.