Skip to Content

version()

Get the version of Nebula. Can return the version number, or commit date of the version.

PHP July 26, 2017

Usage

PHP
nebula()->version($return)

Parameters

$return
(Optional) (Boolean) What value should be returned.
Default: false

Parameter Notes

Possible $return values include “raw”, “version”, “full”, “date”, “time”, and “utc”.

Leaving it empty or passing false will return an array of all version information.

Request or provide clarification »

Examples

Return the month, day, and year of the Nebula version.

PHP
<?php echo nebula()->version('date'); ?>

Additional Notes

Like WordPress, Nebula has a time-based version number. Every May, a major version is released. Likewise, each month a minor version is released. The third number represents the day of the month that Nebula was updated.

Source File

Located in /libs/Utilities/Utilities.php on line 1173.

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_version"
Need a new filter hook? Request one here.

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

PHP
        public function version($return=false){
            $override = apply_filters('pre_nebula_version', null, $return);
            if ( isset($override) ){return $override;}

            $return = str_replace(array(' ', '_', '-'), '', strtolower($return));

            if ( $return === 'child' && is_child_theme() ){
                return $this->child_version();
            }

            $nebula_theme_info = ( is_child_theme() )? wp_get_theme(str_replace('-child', '', get_template())) : wp_get_theme(); //Get the parent theme (regardless of if child theme is active)

            if ( $return === 'raw' ){ //Check this first to prevent needing to RegEx altogether
                return $nebula_theme_info->get('Version'); //Ex: 7.2.23.8475u
            }

            preg_match('/(?<primary>(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+[a-z]?))\.?(?<build>\d+)?/i', $nebula_theme_info->get('Version'), $nebula_version);
            $nebula_version['patch'] = preg_replace('/\D/', '', $nebula_version['patch']); //Remove letters from patch number

            $nebula_version_year = ( $nebula_version['minor'] >= 8 )? 2012+$nebula_version['major']+1 : 2012+$nebula_version['major'];
            $nebula_months = array('May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', 'January', 'February', 'March', 'April');
            $nebula_version_month = $nebula_months[$nebula_version['minor']%12]; //Modulo 12 so the version can go beyond 11 (and still match the appropriate month)
            $nebula_version_day = ( empty($nebula_version['patch']) )? '' : $nebula_version['patch'];
            $nebula_version_day_formated = ( empty($nebula_version['patch']) )? ' ' : ' ' . $nebula_version['patch'] . ', ';

            $nebula_version_info = array(
                'full' => $nebula_version[0],
                'primary' => $nebula_version['primary'],
                'major' => $nebula_version['major'],
                'minor' => $nebula_version['minor'],
                'patch' => $nebula_version['patch'],
                'build' => ( isset($nebula_version['build']) )? $nebula_version['build'] : false,
                'utc' => strtotime($nebula_version_month . $nebula_version_day_formated . $nebula_version_year),
                'date' => $nebula_version_month . $nebula_version_day_formated . $nebula_version_year,
                'year' => $nebula_version_year,
                'month' => $nebula_version_month,
                'day' => $nebula_version_day,
            );

            switch ( $return ){
                case ('raw'): //Shouldn't ever reach this. See early return above.
                    return $nebula_theme_info->get('Version'); //Ex: 7.2.19.8475u
                case ('version'):
                case ('full'):
                    return $nebula_version_info['full']; //Ex: 7.2.23.8475
                case ('primary'):
                    return $nebula_version_info['primary']; //Ex: 7.2.23
                case ('date'):
                    return $nebula_version_info['date']; //Ex: July 23, 2019
                case ('time'):
                case ('utc'):
                    return $nebula_version_info['utc']; //Ex: 1559275200
                default:
                    return $nebula_version_info;
            }
        }

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_version', 'my_custom_version', 10, 2); //The last integer must be 1 more than the actual parameters
function my_custom_version($null, $return){ //$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_version', '__return_false');