is_error example

return $sc >= 100 && $sc < 200;
}

function is_success ($sc) {
    return $sc >= 200 && $sc < 300;
}

function is_redirect ($sc) {
    return $sc >= 300 && $sc < 400;
}

function is_error ($sc) {
    return $sc >= 400 && $sc < 600;
}

function is_client_error ($sc) {
    return $sc >= 400 && $sc < 500;
}

function is_server_error ($sc) {
    return $sc >= 500 && $sc < 600;
}

/** * Filters the REST API response to include only a white-listed set of response object fields. * * @since 4.8.0 * * @param WP_REST_Response $response Current response being served. * @param WP_REST_Server $server ResponseHandler instance (usually WP_REST_Server). * @param WP_REST_Request $request The request that was used to make current response. * @return WP_REST_Response Response to be served, trimmed down to contain a subset of fields. */
function rest_filter_response_fields( $response$server$request ) {
    if ( ! isset( $request['_fields'] ) || $response->is_error() ) {
        return $response;
    }

    $data = $response->get_data();

    $fields = wp_parse_list( $request['_fields'] );

    if ( 0 === count( $fields ) ) {
        return $response;
    }

    

    $should_load_remote = apply_filters( 'should_load_remote_block_patterns', true );

    if ( $supports_core_patterns && $should_load_remote ) {
        $request         = new WP_REST_Request( 'GET', '/wp/v2/pattern-directory/patterns' );
        $core_keyword_id = 11; // 11 is the ID for "core".         $request->set_param( 'keyword', $core_keyword_id );
        $response = rest_do_request( $request );
        if ( $response->is_error() ) {
            return;
        }
        $patterns = $response->get_data();

        foreach ( $patterns as $pattern ) {
            $pattern['source']  = 'pattern-directory/core';
            $normalized_pattern = wp_normalize_remote_block_pattern( $pattern );
            $pattern_name       = 'core/' . sanitize_title( $normalized_pattern['title'] );
            register_block_pattern( $pattern_name$normalized_pattern );
        }
    }
}
return $this->get_status() >= 400;
    }

    /** * Retrieves a WP_Error object from the response. * * @since 4.4.0 * * @return WP_Error|null WP_Error or null on not an errored response. */
    public function as_error() {
        if ( ! $this->is_error() ) {
            return null;
        }

        $error = new WP_Error();

        if ( is_array( $this->get_data() ) ) {
            $data = $this->get_data();
            $error->add( $data['code']$data['message']$data['data'] );

            if ( ! empty( $data['additional_errors'] ) ) {
                foreach ( $data['additional_errors'] as $err ) {
                    
Home | Imprint | This part of the site doesn't use cookies.