Skip to Content

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!

Source File

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

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');
            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/' . $_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($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] === 443 ){
                $secureServer = '<small class="secured-connection"><i class="fas fa-fw fa-lock"></i>Secured Connection</small>';
            }
            echo '<li><i class="fas fa-fw fa-upload"></i> Server IP: <strong><a href="http://whatismyipaddress.com/ip/' . $_SERVER['SERVER_ADDR'] . '" target="_blank" rel="noopener noreferrer">' . apply_filters('nebula_dashboard_server_ip', $_SERVER['SERVER_ADDR']) . '</a></strong> ' . $secureServer . '</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 = $_SERVER['SERVER_SOFTWARE'];
            if ( strlen($server_software) > 10 ){
                $server_software = strtok($_SERVER['SERVER_SOFTWARE'], ' '); //Shorten to until the first space
            }
            echo '<li><i class="fas fa-fw fa-server"></i> Server Software: <strong title="' . $_SERVER['SERVER_SOFTWARE'] . '">' . $server_software . '</strong></li>';

            echo '<li><i class="fas fa-fw fa-ethernet"></i> Server Protocol: <strong>' . $_SERVER['SERVER_PROTOCOL'] . '</strong></li>';

            //MySQL version
            if ( function_exists('mysqli_get_client_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 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 = get_transient('nebula_directory_size_parent_theme');
                if ( empty($nebula_parent_size) || $this->is_debug() ){
                    $nebula_parent_size = $this->foldersize(get_template_directory());
                    set_transient('nebula_directory_size_parent_theme', $nebula_parent_size, DAY_IN_SECONDS);
                }

                $nebula_child_size = get_transient('nebula_directory_size_child_theme');
                if ( empty($nebula_child_size) || $this->is_debug() ){
                    $nebula_child_size = $this->foldersize(get_stylesheet_directory());
                    set_transient('nebula_directory_size_child_theme', $nebula_child_size, DAY_IN_SECONDS);
                }

                echo '<li><i class="fas fa-code"></i> Parent theme directory size: <strong>' . round($nebula_parent_size/1048576, 2) . 'mb</strong> </li>';
                echo '<li><i class="fas fa-code"></i> Child theme directory size: <strong>' . round($nebula_child_size/1048576, 2) . 'mb</strong> </li>';
            } else {
                $nebula_size = get_transient('nebula_directory_size_theme');
                if ( empty($nebula_size) || $this->is_debug() ){
                    $nebula_size = $this->foldersize(get_stylesheet_directory());
                    set_transient('nebula_directory_size_theme', $nebula_size, DAY_IN_SECONDS);
                }
                echo '<li><i class="fas fa-code"></i> Theme directory size: <strong>' . round($nebula_size/1048576, 2) . 'mb</strong> </li>';
            }

            do_action('nebula_dev_dashboard_directories');

            //Uploads directory size (and max upload size)
            $upload_dir = wp_upload_dir();
            $uploads_size = get_transient('nebula_directory_size_uploads');
            if ( empty($uploads_size) || $this->is_debug() ){
                $uploads_size = $this->foldersize($upload_dir['basedir']);
                set_transient('nebula_directory_size_uploads', $uploads_size, HOUR_IN_SECONDS*36);
            }

            if ( function_exists('wp_max_upload_size') ){
                $upload_max = '<small>(Max upload: <strong>' . strval(round((int) wp_max_upload_size()/(1024*1024))) . 'mb</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>' . round($uploads_size/1048576, 2) . 'mb</strong> ' . $upload_max . '</li>';

            //PHP Disk Space
            $disk_total_space = disk_total_space(ABSPATH)/1073741824; //In GB
            $disk_free_space = disk_free_space(ABSPATH)/1073741824; //In GB

            $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 . ';">' . round($disk_free_space, 2) . 'gb</strong> <small>(Total space: <strong>' . round($disk_total_space, 0) . 'gb</strong>)</small></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" type="submit" value="Search" /></form>';
            echo '<div class="search_results"></div>';
            $this->timer('Nebula Developer Dashboard', 'end');
        }

Override

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