Usage
nebula()->php_version_support($php_version)
Parameters
$php_version
(Optional) (String) The PHP version to check against
Default: PHP_VERSION
Examples
$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 1459.
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?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 = nebula()->transient('nebula_php_timeline', function(){ $php_timeline_json_file = get_template_directory() . '/inc/data/php_timeline.json'; //This local JSON file will either be updated or used directly later global $wp_filesystem; WP_Filesystem(); $response = $this->remote_get('https://raw.githubusercontent.com/chrisblakley/Nebula/main/inc/data/php_timeline.json'); //Get the latest JSON file from Nebula GitHub if ( !is_wp_error($response) && isset($response['body']) ){ $php_timeline = $response['body']; if ( !empty($php_timeline) ){ $wp_filesystem->put_contents($php_timeline_json_file, $php_timeline); //Update the local JSON file with the new remote file return $php_timeline; } } return $wp_filesystem->get_contents($php_timeline_json_file); //Otherwise use the existing local JSON file }, MONTH_IN_SECONDS); $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):
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:
add_filter('pre_nebula_php_version_support', '__return_false');