Skip to Content
Menu

last_modified()

Get last modified filename and date from a directory

PHP March 16, 2017

Usage

PHP
nebula()->last_modified($directory, $last_date, $child)

Parameters

$directory
(Optional) (String) The directory to check
Default: None

$last_date
(Optional) (Integer) The time of the last modified file
Default: None

$child
(Optional) (Boolean) Whether to check the child theme.
Default: false

Request or provide clarification »

Additional Notes

This function shouldn’t need to be called manually.

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /libs/Admin/Dashboard.php on line 846.

    No Hooks

    This function does not have any filters or actions available. Request one?

    Note: This function contains 1 to-do comment.

    PHP
            public function last_modified($directory=null, $last_date=0, $child=false){
                global $latest_file;
                if ( empty($latest_file) ){
                    $latest_file = array(
                        'date' => false,
                        'file' => false,
                        'path' => false,
                    );
                }
    
                //@todo "Nebula" 0: Use null coalescing operator here
                if ( empty($directory) ){
                    $directory = get_template_directory();
                }
                $dir = $this->glob_r($directory . '/*');
                $skip_files = array('/cache/', '/includes/data/', 'manifest.json', '.bak'); //Files or directories to skip. Be specific!
    
                foreach ( $dir as $file ){
                    if ( is_file($file) ){
                        $mod_date = filemtime($file);
                        if ( $mod_date > $last_date && !$this->contains($file, $skip_files) ){ //Does not check against skip_extensions() functions on purpose.
                            $latest_file['date'] = $mod_date;
                            $latest_file['file'] = basename($file);
    
                            if ( is_child_theme() && $child ){
                                $latest_file['path'] = 'Child: ';
                            } elseif ( is_child_theme() && !$child ){
                                $latest_file['path'] = 'Parent: ';
                            }
                            $latest_file['path'] .= str_replace($directory, '', dirname($file)) . '/' . $latest_file['file'];
    
                            $last_date = $latest_file['date'];
                        }
                    }
                }
    
                if ( is_child_theme() && !$child ){
                    $latest_child_file = $this->last_modified(get_stylesheet_directory(), $latest_file['date'], true);
                    if ( $latest_child_file['date'] > $latest_file['date'] ){
                        return $latest_child_file;
                    }
                }
    
                return $latest_file;
            }
    

    Override

    This function can not be short-circuited with an override filter. Request one?