Using WordPress ‘is_info()’ PHP function

The is_info() WordPress PHP function is used to determine if an HTTP response code is informational (i.e., between 100 and 199, inclusive). It returns true if the condition is met, and false otherwise.

Usage

is_info($sc);

Example:

Input:

is_info(150);

Output:

true

Parameters

  • $sc integer – The HTTP response code to be checked.

More information

See WordPress Developer Resources: is_info()

Examples

Check if the response code is informational

This code checks if the response code 100 is informational.

$response_code = 100;
if (is_info($response_code)) {
    echo "The response code is informational.";
} else {
    echo "The response code is not informational.";
}

Handle different response codes

This code handles different response codes and checks if they are informational.

$response_codes = [100, 150, 199, 200, 404];
foreach ($response_codes as $code) {
if (is_info($code)) {
echo "The response code $code is informational.\n";
} else {
echo "The response code $code is not informational.\n";
}
}

Function to categorize response codes

This code defines a function to categorize HTTP response codes and uses is_info() to determine if a response code is informational.

function categorize_response_code($code) {
    if (is_info($code)) {
        return "Informational";
    }
    // Other conditions to categorize response codes
}
$response_code = 150;
$category = categorize_response_code($response_code);
echo "The response code $response_code is $category.";

Logging informational response codes

This code logs informational response codes using is_info() and a custom logging function.

function custom_log($message) {
    // Your custom logging implementation
}
$response_codes = [100, 150, 199, 200, 404];
foreach ($response_codes as $code) {
if (is_info($code)) {
custom_log("Informational response code: $code");
}
}

Filtering informational response codes

This code filters an array of response codes to keep only informational response codes using is_info().

$response_codes = [100, 150, 199, 200, 404];
$informational_codes = array_filter($response_codes, 'is_info');
print_r($informational_codes);