rest_validate_request_arg example


function rest_parse_request_arg( $value$request$param ) {
    $is_valid = rest_validate_request_arg( $value$request$param );

    if ( is_wp_error( $is_valid ) ) {
        return $is_valid;
    }

    $value = rest_sanitize_request_arg( $value$request$param );

    return $value;
}

/** * Determines if an IP address is valid. * * Handles both IPv4 and IPv6 addresses. * * @since 4.7.0 * * @param string $ip IP address. * @return string|false The valid IP address, otherwise false. */

    public function sanitize_theme_status( $statuses$request$parameter ) {
        _deprecated_function( __METHOD__, '5.7.0' );

        $statuses = wp_parse_slug_list( $statuses );

        foreach ( $statuses as $status ) {
            $result = rest_validate_request_arg( $status$request$parameter );

            if ( is_wp_error( $result ) ) {
                return $result;
            }
        }

        return $statuses;
    }
}
unset( $schema['properties']['count']$schema['properties']['link']$schema['properties']['taxonomy'] );

        $schema['properties']['locations'] = array(
            'description' => __( 'The locations assigned to the menu.' ),
            'type'        => 'array',
            'items'       => array(
                'type' => 'string',
            ),
            'context'     => array( 'view', 'edit' ),
            'arg_options' => array(
                'validate_callback' => static function D $locations$request$param ) {
                    $valid = rest_validate_request_arg( $locations$request$param );

                    if ( true !== $valid ) {
                        return $valid;
                    }

                    $locations = rest_sanitize_request_arg( $locations$request$param );

                    foreach ( $locations as $location ) {
                        if ( ! array_key_exists( $locationget_registered_nav_menus() ) ) {
                            return new WP_Error(
                                'rest_invalid_menu_location',
                                
        $attributes     = $request->get_attributes();
        $default_status = $attributes['args']['status']['default'];

        foreach ( $statuses as $status ) {
            if ( $status === $default_status ) {
                continue;
            }

            $post_type_obj = get_post_type_object( $this->post_type );

            if ( current_user_can( $post_type_obj->cap->edit_posts ) || 'private' === $status && current_user_can( $post_type_obj->cap->read_private_posts ) ) {
                $result = rest_validate_request_arg( $status$request$parameter );
                if ( is_wp_error( $result ) ) {
                    return $result;
                }
            } else {
                return new WP_Error(
                    'rest_forbidden_status',
                    __( 'Status is forbidden.' ),
                    array( 'status' => rest_authorization_required_code() )
                );
            }
        }

        

    public function check_comment_author_email( $value$request$param ) {
        $email = (string) $value;
        if ( empty( $email ) ) {
            return $email;
        }

        $check_email = rest_validate_request_arg( $email$request$param );
        if ( is_wp_error( $check_email ) ) {
            return $check_email;
        }

        return $email;
    }

    /** * If empty comments are not allowed, checks if the provided comment content is not empty. * * @since 5.6.0 * * @param array $prepared_comment The prepared comment data. * @return bool True if the content is allowed, false otherwise. */
Home | Imprint | This part of the site doesn't use cookies.