This website uses cookies to allow us to see how the site is used. If you continue to use this site, we assume that you are okay with this. If you want to use the sites without cookies, please see our privacy policy.

Add cURL version to Site Health Checker

This snippet shows you how you can easily extend the “tests” within the Site Health testing area. The cURL version is really important for secure communications with third-party sites like payment gateways, and it is part of what makes your https connections strong and secure.

/**
  * Adds a cURL version test to Site Health
  *
  * Info here: https://make.wordpress.org/core/2019/04/25/site-health-check-in-5-2/
  * NOTE: Requires version 5.2+ of WordPress 
  *
 **/
function register_give_curl_tester( $tests ) {
    $tests['direct']['curl_tester'] = array(
        'label' => __( 'Test cURL' ),
        'test'  => 'give_test_curl_version',
    );
    return $tests;
}
add_filter( 'site_status_tests', 'register_give_curl_tester' );
function give_test_curl_version() {
    $results = array(
        'label'       => __( 'cURL Version' ),
        'status'      => 'good',
        'badge'       => array(
            'label' => __( 'Security' ),
            'color' => 'blue',
        ),
        'description' => sprintf(
            '<p>' .  __( 'Your cURL version is: ', 'give' ) . '%g -- this meets or exceeds the minimum requirement for secure online donations.</p>', curl_version()['version']),
        'actions'     => '',
        'test'        => 'curl_tester',
    );
    $curl_version = curl_version()['version'];
    if ( $curl_version < '7.40' ) {
        $results['status'] = 'critical';
        $results['label'] = __( 'cURL version is outdated' );
        $results['description'] = sprintf(
            '<p>' .  __( 'Your cURL version is: ', 'give' ) . '%g</p>', curl_version()['version']);
        $results['actions'] = sprintf(
            '<p>%s</p>',
            __( 'Your cURL version is outdated. This can negatively impact your online donations with GiveWP. Please contact your host about getting cURL updated to at least version 7.40.', 'give' )
        );
        $results['badge']['color'] = 'red';
    }
    return $results;
}