rest_is_ip_address example

if ( ! rest_parse_date( $value ) ) {
                    return new WP_Error( 'rest_invalid_date', __( 'Invalid date.' ) );
                }
                break;

            case 'email':
                if ( ! is_email( $value ) ) {
                    return new WP_Error( 'rest_invalid_email', __( 'Invalid email address.' ) );
                }
                break;
            case 'ip':
                if ( ! rest_is_ip_address( $value ) ) {
                    /* translators: %s: IP address. */
                    return new WP_Error( 'rest_invalid_ip', sprintf( __( '%s is not a valid IP address.' )$param ) );
                }
                break;
            case 'uuid':
                if ( ! wp_is_uuid( $value ) ) {
                    /* translators: %s: The name of a JSON field expecting a valid UUID. */
                    return new WP_Error( 'rest_invalid_uuid', sprintf( __( '%s is not a valid UUID.' )$param ) );
                }
                break;
        }
    }
if ( isset( $request['author_email'] ) ) {
            $prepared_comment['comment_author_email'] = $request['author_email'];
        }

        if ( isset( $request['author_url'] ) ) {
            $prepared_comment['comment_author_url'] = $request['author_url'];
        }

        if ( isset( $request['author_ip'] ) && current_user_can( 'moderate_comments' ) ) {
            $prepared_comment['comment_author_IP'] = $request['author_ip'];
        } elseif ( ! empty( $_SERVER['REMOTE_ADDR'] ) && rest_is_ip_address( $_SERVER['REMOTE_ADDR'] ) ) {
            $prepared_comment['comment_author_IP'] = $_SERVER['REMOTE_ADDR'];
        } else {
            $prepared_comment['comment_author_IP'] = '127.0.0.1';
        }

        if ( ! empty( $request['author_user_agent'] ) ) {
            $prepared_comment['comment_agent'] = $request['author_user_agent'];
        } elseif ( $request->get_header( 'user_agent' ) ) {
            $prepared_comment['comment_agent'] = $request->get_header( 'user_agent' );
        }

        
Home | Imprint | This part of the site doesn't use cookies.