Skip to Content

php_version_support()

Check the current (or a specifc) PHP version against the PHP support timeline.

PHP June 18, 2017

Usage

PHP
nebula()->php_version_support($php_version)

Parameters

$php_version
(Optional) (String) The PHP version to check against
Default: PHP_VERSION

Request or provide clarification »

Examples

PHP
$php_version_lifecycle = nebula()->php_version_support();
if ( $php_version_lifecycle['lifecycle'] === 'end' ){
    //Do something if this version of php is no longer maintained (does not receive security updates)
}

Additional Notes

This function returns an array of lifecycle, security, and end.

Lifecycle is what stage that version is in: active, security, or end.

Security is the date when security updates stop.

End is the date when that version is no longer maintained.

Source File

Located in /libs/Admin/Admin.php on line 1294.

1 Hook

Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.

Filters
"pre_nebula_php_version_support"
Need a new filter hook? Request one here.

Actions
This function has no action hooks available. Request one?

PHP
        public function php_version_support($php_version=PHP_VERSION){
            $override = apply_filters('pre_nebula_php_version_support', null, $php_version);
            if ( isset($override) ){return;}

            $php_timeline_json_file = get_template_directory() . '/inc/data/php_timeline.json';
            $php_timeline = get_transient('nebula_php_timeline');
            if ( empty($php_timeline) || $this->is_debug() ){
                $response = $this->remote_get('https://raw.githubusercontent.com/chrisblakley/Nebula/master/inc/data/php_timeline.json');
                if ( !is_wp_error($response) ){
                    $php_timeline = $response['body'];
                }

                WP_Filesystem();
                global $wp_filesystem;
                if ( !empty($php_timeline) ){
                    $wp_filesystem->put_contents($php_timeline_json_file, $php_timeline); //Store it locally.
                    set_transient('nebula_php_timeline', $php_timeline, YEAR_IN_SECONDS/12); //1 month cache
                } else {
                    $php_timeline = $wp_filesystem->get_contents($php_timeline_json_file);
                }
            }

            $php_timeline = json_decode($php_timeline);
            if ( !empty($php_timeline) ){
                preg_match('/^(?<family>\d\.\d)\.?/i', PHP_VERSION, $current_php_version); //Grab the major/minor version of this PHP

                if ( isset($php_timeline[0]->{$current_php_version['family']}) ){ //If this version of PHP is in the local JSON file
                    $php_version_info = $php_timeline[0]->{$current_php_version['family']}; //Find this major/minor version "family" of PHP in the JSON

                    if ( !empty($php_version_info) ){ //If a match for this PHP version "family" was found in the JSON data
                        $output = array();

                        if ( !empty($php_version_info->security) && time() < strtotime($php_version_info->security) ){
                            $output['lifecycle'] = 'active';
                        } elseif ( !empty($php_version_info->security) && (time() >= strtotime($php_version_info->security) && time() < strtotime($php_version_info->end)) ){
                            $output['lifecycle'] = 'security';
                        } elseif ( time() >= strtotime($php_version_info->end) ){
                            $output['lifecycle'] = 'end';
                        } else {
                            $output['lifecycle'] = 'unknown'; //An error of some kind has occurred.
                        }

                        $output['security'] = strtotime($php_version_info->security);
                        $output['end'] = strtotime($php_version_info->end);

                        return $output;
                    }
                }
            }

            return false;
        }

Override

To override this PHP function, use this hook in your child theme or plugin ("my_custom" can be changed):

PHP
add_filter('pre_nebula_php_version_support', 'my_custom_php_version_support', 10, 2); //The last integer must be 1 more than the actual parameters
function my_custom_php_version_support($null, $php_version){ //$null is required, but can be ignored
    //Write your own code here

    return true; //Return true to prevent the original function from running afterwords
}

You can completely disable this PHP function with a single line actions:

PHP
 add_filter('pre_nebula_php_version_support', '__return_false');