Skip to Content
Menu

dashboard_developer_info()

PHP October 10, 2017

Usage

This function runs automatically, so it is not called manually. Is this incorrect?

Additional Notes

This dashboard metabox must be enabled in Nebula Options, and either a developer IP or email domain must be entered!

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 575.

    4 Hooks

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

    Actions
    "nebula_developer_info"
    "nebula_dev_dashboard_directories"
    Need a new action hook? Request one here.

    Note: This function contains 1 to-do comment.

    PHP
            public function dashboard_developer_info(){
                $this->timer('Nebula Developer Dashboard Metabox');
                do_action('nebula_developer_info');
                echo '<ul class="nebula-fa-ul serverdetections">';
    
                //Environment Type
                if ( function_exists('wp_get_environment_type') ){ //New as of WP 5.5 (August 2020). Remove this conditional eventually.
                    $environment_type = ucwords(wp_get_environment_type());
                    $environment_type_icon = 'fa-industry'; //Assume "Production" by default
                    if ( $environment_type === 'Staging' ){
                        $environment_type_icon = 'fa-pencil-ruler';
                    } elseif ( $environment_type === 'Development' ){
                        $environment_type_icon = 'fa-hard-hat';
                    } elseif ( $environment_type === 'Test' ){
                        $environment_type_icon = 'fa-flask';
                    }
    
                    echo '<li><i class="fas fa-fw ' . $environment_type_icon . '"></i> Environment Type: <strong>' . $environment_type . '</strong></li>';
                }
    
                //Domain
                //@todo "Nebula" 0: Use null coalescing operator here if possible
                $domain = $this->url_components('domain');
                if ( empty($domain) ){
                    $domain = '<small>(None)</small>';
                }
                echo '<li><i class="fas fa-fw fa-info-circle"></i> <a href="http://whois.domaintools.com/' . $this->super->server['SERVER_NAME'] . '" target="_blank" rel="noopener noreferrer" title="WHOIS Lookup">Domain</a>: <strong>' . $domain . '</strong></li>';
    
                //Host
                function top_domain_name($url){
                    $alldomains = explode('.', $url);
    
                    if ( count($alldomains) > 1 ){
                        return $alldomains[count($alldomains)-2] . "." . $alldomains[count($alldomains)-1];
                    }
    
                    return $url;
                }
    
                if ( function_exists('gethostname') ){
                    set_error_handler(function(){ /* ignore errors */ });
                    $dnsrecord = ( dns_get_record(top_domain_name(gethostname()), DNS_NS) )? dns_get_record(top_domain_name(gethostname()), DNS_NS) : '';
                    restore_error_handler();
    
                    echo '<li><i class="far fa-fw fa-hdd"></i> Host: <strong>' . top_domain_name(gethostname()) . '</strong>';
                    if ( !empty($dnsrecord[0]['target']) ){
                        echo ' <small>(' . top_domain_name($dnsrecord[0]['target']) . ')</small>';
                    }
                    echo '</li>';
                }
    
                //Server IP address (and connection security)
                $secureServer = '';
                if ( (!empty($this->super->server['HTTPS']) && $this->super->server['HTTPS'] !== 'off') || $this->super->server['SERVER_PORT'] === 443 ){
                    $secureServer = '<small class="secured-connection"><i class="fas fa-fw fa-lock"></i>Secured Connection</small>';
                }
                $public_local_ip = ( preg_match('/^(127\.|192\.168|172\.|10\.)/', $this->super->server['SERVER_ADDR']) )? 'Local' : 'Public'; //Check if the server IP is likely local (private) or public (this is not perfectly exact)
                echo '<li><i class="fas fa-fw fa-upload"></i> ' . $public_local_ip . ' Server IP: <strong><a href="http://whatismyipaddress.com/ip/' . $this->super->server['SERVER_ADDR'] . '" target="_blank" rel="noopener noreferrer">' . apply_filters('nebula_dashboard_server_ip', $this->super->server['SERVER_ADDR']) . '</a></strong> ' . $secureServer . '</li>';
    
                //Server Time Zone
                if ( date_default_timezone_get() === get_option('timezone_string') ){
                    echo '<li><i class="fas fa-fw fa-globe-americas"></i> Timezone: <strong>' . date_default_timezone_get() . '</strong></li>';
                } else {
                    echo '<li><i class="fas fa-fw fa-globe-americas"></i> Server Timezone: <strong>' . date_default_timezone_get() . '</strong></li>';
                    echo '<li><i class="fas fa-fw fa-globe-americas"></i> WordPress Timezone: <strong>' . get_option('timezone_string') . '</strong></li>';
                }
    
                //Server operating system
                if ( strpos(strtolower(PHP_OS), 'linux') !== false ){
                    $php_os_icon = 'fa-linux';
                } elseif ( strpos(strtolower(PHP_OS), 'windows') !== false ){
                    $php_os_icon = 'fa-windows';
                } else {
                    $php_os_icon = 'fa-upload';
                }
                echo '<li><i class="fab fa-fw ' . $php_os_icon . '"></i> Server OS: <strong>' . PHP_OS . '</strong></li>';
    
                //Server software
                $server_software = $this->super->server['SERVER_SOFTWARE'];
                if ( strlen($server_software) > 10 ){
                    $server_software = strtok($this->super->server['SERVER_SOFTWARE'], ' '); //Shorten to until the first space
                }
                echo '<li><i class="fas fa-fw fa-server"></i> Server Software: <strong title="' . $this->super->server['SERVER_SOFTWARE'] . '">' . $server_software . '</strong></li>';
    
                echo '<li><i class="fas fa-fw fa-ethernet"></i> Server Protocol: <strong>' . $this->super->server['SERVER_PROTOCOL'] . '</strong></li>';
    
                //MySQL version
                $mysql_version = mysqli_get_client_version();
                echo '<li><i class="fas fa-fw fa-database"></i> MySQL Version: <strong title="Raw: ' . $mysql_version . '">' . floor($mysql_version/10000) . '.' . floor(($mysql_version%10000)/100) . '.' . ($mysql_version%10000)%100 . '</strong></li>'; //PHP 7.4 use numeric separators here
    
                //PHP version
                $php_version_color = 'inherit';
                $php_version_info = '';
                $php_version_cursor = 'normal';
                $php_version_lifecycle = $this->php_version_support();
                if ( !empty($php_version_lifecycle) ){
                    if ( $php_version_lifecycle['lifecycle'] === 'security' ){
                        $php_version_color = '#ca8038'; //Warning
                        $php_version_info = 'This version is nearing end of life. Security updates end on ' . date('F j, Y', $php_version_lifecycle['end']) . '.';
                        $php_version_cursor = 'help';
                    } elseif ( $php_version_lifecycle['lifecycle'] === 'end' ){
                        $php_version_color = '#ca3838'; //Danger
                        $php_version_info = 'This version no longer receives security updates! End of life occurred on ' . date('F j, Y', $php_version_lifecycle['end']) . '.';
                        $php_version_cursor = 'help';
                    }
                }
                echo '<li><i class="fas fa-fw fa-wrench"></i> PHP Version: <strong style="color: ' . $php_version_color . '; cursor: ' . $php_version_cursor . ';" title="' . $php_version_info . '">' . PHP_VERSION . '</strong></li>';
    
                //PHP memory limit
                echo '<li><i class="fas fa-fw fa-cogs"></i> PHP Memory Limit: <strong>' . WP_MEMORY_LIMIT . '</strong></li>';
    
                //Theme directory size(s)
                if ( is_child_theme() ){
                    $nebula_parent_size = nebula()->transient('nebula_directory_size_parent_theme', function(){
                        return $this->foldersize(get_template_directory());
                    }, DAY_IN_SECONDS);
    
                    $nebula_child_size = nebula()->transient('nebula_directory_size_child_theme', function(){
                        return $this->foldersize(get_stylesheet_directory());
                    }, DAY_IN_SECONDS);
    
                    echo '<li><i class="fas fa-code"></i> Parent theme directory size: <strong>' . $this->format_bytes($nebula_parent_size, 1) . '</strong> </li>';
                    echo '<li><i class="fas fa-code"></i> Child theme directory size: <strong>' . $this->format_bytes($nebula_child_size, 1) . '</strong> </li>';
                } else {
                    $nebula_size = nebula()->transient('nebula_directory_size_theme', function(){
                        return $this->foldersize(get_stylesheet_directory());
                    }, DAY_IN_SECONDS);
                    echo '<li><i class="fas fa-code"></i> Theme directory size: <strong>' . $this->format_bytes($nebula_size, 1) . '</strong> </li>';
                }
    
                do_action('nebula_dev_dashboard_directories');
    
                //Uploads directory size (and max upload size)
                $uploads_size = nebula()->transient('nebula_directory_size_uploads', function(){
                    $upload_dir = wp_upload_dir();
                    return $this->foldersize($upload_dir['basedir']);
                }, HOUR_IN_SECONDS*36);
    
                //Here is how it will be after the next major version release:
                // $uploads_size = $this->transient('nebula_directory_size_uploads', function(){
                //     $upload_dir = wp_upload_dir();
                //     return $this->foldersize($upload_dir['basedir']);
                // }, HOUR_IN_SECONDS*36);
    
                if ( function_exists('wp_max_upload_size') ){
                    $upload_max = '<small>(Max upload: <strong>' . $this->format_bytes(((int) wp_max_upload_size())) . '</strong>)</small>';
                } elseif ( ini_get('upload_max_filesize') ){
                    $upload_max = '<small>(Max upload: <strong>' . ini_get('upload_max_filesize') . '</strong>)</small>';
                } else {
                    $upload_max = '';
                }
                echo '<li><i class="fas fa-fw fa-images"></i> Uploads directory size: <strong>' . $this->format_bytes($uploads_size, 1) . '</strong> ' . $upload_max . '</li>';
    
                //PHP Disk Space
                if ( function_exists('disk_total_space') && function_exists('disk_free_space') ){
                    $disk_total_space = disk_total_space(ABSPATH);
                    $disk_free_space = disk_free_space(ABSPATH);
    
                    $disk_usage_color = 'inherit';
                    if ( $disk_free_space < 5 ){
                        $disk_usage_color = '#ca3838'; //Danger
                    } elseif ( $disk_free_space < 10 ){
                        $disk_usage_color = '#ca8038'; //Warning
                    }
    
                    echo '<li><i class="fas fa-fw fa-hdd"></i> Disk Space Available: <strong style="color: ' . $disk_usage_color . ';">' . $this->format_bytes($disk_free_space, 1) . '</strong> <small>(Total space: <strong>' . $this->format_bytes($disk_total_space) . '</strong>)</small></li>';
                }
    
                //Log Files
                foreach ( $this->get_log_files('all', true) as $types ){ //Always get fresh data here
                    foreach ( $types as $log_file ){
                        echo '<li><i class="far fa-fw fa-file-alt"></i> <code title="' . $log_file['shortpath'] . '" style="cursor: help;">' . $log_file['name'] . '</code> File: <strong>' . $this->format_bytes($log_file['bytes']) . '</strong></li>';
                    }
                }
    
                //Service Worker
                if ( $this->get_option('service_worker') ){
                    if ( !is_ssl() ){
                        echo '<li><i class="fas fa-fw fa-microchip" style="color: red;"></i> <strong>Not</strong> using service worker. No SSL.</li>';
                    } elseif ( !file_exists($this->sw_location(false)) ){
                        echo '<li><i class="fas fa-fw fa-microchip" style="color: red;"></i> <strong>Not</strong> using service worker. Service worker file does not exist.</li>';
                    } else {
                        echo '<li><i class="fas fa-fw fa-microchip"></i> Using service worker</li>';
                    }
                }
    
                //Initial installation date
                function initial_install_date(){
                    $nebula_initialized = nebula()->get_option('initialized'); //Keep this as nebula() because it is a nested function, so $this is scoped differently here.
                    if ( !empty($nebula_initialized) && $nebula_initialized < getlastmod() ){
                        $install_date = '<span title="' . date('F j, Y', $nebula_initialized) . ' @ ' . date('g:ia', $nebula_initialized) . '" style="cursor: help;"><strong>' . human_time_diff($nebula_initialized) . ' ago</strong></span>';
                    } else { //Use the last modified time of the admin page itself
                        $install_date = '<span title="' . date("F j, Y", getlastmod()) . ' @ ' . date("g:ia", getlastmod()) . '" style="cursor: help;"><strong>' . human_time_diff(getlastmod()) . ' ago</strong></span>';
                    }
                    return $install_date;
                }
                echo '<li><i class="far fa-fw fa-calendar"></i> Installed: ' . initial_install_date() . '</li>';
    
                $latest_file = $this->last_modified();
                echo '<li><i class="far fa-fw fa-calendar"></i> <span title="' . $latest_file['path'] . '" style="cursor: help;">Modified:</span> <span title="' . date("F j, Y", $latest_file['date']) . ' @ ' . date("g:ia", $latest_file['date']) . '" style="cursor: help;"><strong>' . human_time_diff($latest_file['date']) . ' ago</strong></span></li>';
    
                //SCSS last processed date
                if ( $this->get_data('scss_last_processed') ){
                    $sass_option = ( nebula()->get_option('scss') )? '' : ' <small><em><a href="themes.php?page=nebula_options&tab=functions&option=scss">Sass is currently <strong>disabled</strong> &raquo;</a></em></small>';
                    echo '<li><i class="fab fa-fw fa-sass"></i> Sass Processed: <span title="' . date("F j, Y", $this->get_data('scss_last_processed')) . ' @ ' . date("g:i:sa", $this->get_data('scss_last_processed')) . '" style="cursor: help;"><strong>' . human_time_diff($this->get_data('scss_last_processed')) . ' ago</strong></span> ' . $sass_option . '</li>';
                }
                echo '</ul>';
    
                //Directory search
                $directory_search_options = array('uploads' => '<option value="uploads">Uploads</option>');
                if ( is_child_theme() ){
                    $directory_search_options['child'] = '<option value="child" selected="selected">Child Theme</option>';
                    $directory_search_options['parent'] = '<option value="parent">Parent Theme</option>';
                } else {
                    $directory_search_options['theme'] = '<option value="theme" selected="selected">Theme</option>';
                }
    
                //Add active plugins to search list
                $directory_search_options['all_plugins'] = '<option value="all_plugins">All Plugins</option>';
                $all_plugins = get_plugins();
                $active_plugins = get_option('active_plugins');
                foreach ( $active_plugins as $active_plugin ){
                    if ( isset($all_plugins[$active_plugin]) ){
                        $plugin_name = $all_plugins[$active_plugin]['Name'];
                        $safe_plugin_name = str_replace(array(' ', '-', '/'), '_', strtolower($plugin_name));
                        $directory_search_options[$safe_plugin_name] = '<option value="' . $safe_plugin_name . '">' . $plugin_name . '</option>';
                    }
                }
    
                $all_directory_search_options = apply_filters('nebula_directory_search_options', $directory_search_options); //Allow other functions to hook in to add directories to search
    
                echo '<form id="theme" class="searchfiles"><i id="searchprogress" class="fas fa-fw fa-search"></i> <input class="findterm" type="text" placeholder="Search files" /><select class="searchdirectory">';
                foreach ( $all_directory_search_options as $name => $option_html ){
                    echo $option_html;
                }
                echo '</select><input class="searchterm button button-primary button-disabled" type="submit" value="Search" title="Still loading... Please wait." /></form>';
                echo '<div class="search_results"></div>';
                $this->timer('Nebula Developer Dashboard Metabox', 'end');
            }
    

    Override

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