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

    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 3 to-do comments.

    PHP
            public function dashboard_developer_info(){
                $this->timer('Nebula Developer Dashboard Metabox');
                do_action('nebula_developer_info');
                echo '<ul class="nebula-fa-ul serverdetections">';
    
                echo '<li class="cookie_notification text_ad ads advertisement ads_content ads_div ads_google adsbygoogle adscontainer adsense-box nebula-adb-tester"></li>'; //Alert developers if their ad-blocker is still active
    
                //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="fa-solid 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="fa-solid 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="fa-regular 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="fa-solid 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="fa-solid 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 ( !empty(get_option('timezone_string')) && date_default_timezone_get() === get_option('timezone_string') && wp_timezone_string() === get_option('timezone_string') ){
                    echo '<li><i class="fa-solid fa-fw fa-globe-americas"></i> Timezone: <strong>' . date_default_timezone_get() . '</strong></li>';
                } else {
                    echo '<li><i class="fa-solid fa-fw fa-globe-americas"></i> Server Timezone: <strong>' . date_default_timezone_get() . '</strong></li>';
                    echo '<li><i class="fa-solid fa-fw fa-globe-americas"></i> WordPress Timezone Option: <strong>' . get_option('timezone_string') . '</strong></li>';
                    echo '<li><i class="fa-solid fa-fw fa-globe-americas"></i> WordPress Timezone String: <strong>' . wp_timezone_string() . '</strong></li>';
                }
    
                //Server operating system
                if ( strpos(strtolower(PHP_OS), 'linux') !== false ){ //@todo "Nebula" 0: Update strpos() to str_contains() in PHP8
                    $php_os_icon = 'fa-brands fa-linux';
                } elseif ( strpos(strtolower(PHP_OS), 'windows') !== false ){ //@todo "Nebula" 0: Update strpos() to str_contains() in PHP8
                    $php_os_icon = 'fa-brands fa-windows';
                } else {
                    $php_os_icon = 'fa-solid fa-upload';
                }
                echo '<li><i class="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="fa-solid fa-fw fa-server"></i> Server Software: <strong title="' . $this->super->server['SERVER_SOFTWARE'] . '">' . $server_software . '</strong></li>';
    
                echo '<li><i class="fa-solid fa-fw fa-ethernet"></i> Server Protocol: <strong>' . $this->super->server['SERVER_PROTOCOL'] . '</strong></li>';
    
                //MySQL version
                global $wpdb;
                $mysql_version = mysqli_get_client_version();
                echo '<li><i class="fa-solid 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> <small>(' . get_class($wpdb->dbh) . ')</small></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="fa-solid fa-fw fa-wrench"></i> PHP Version: <strong style="color: ' . $php_version_color . '; cursor: ' . $php_version_cursor . ';" title="' . $php_version_info . '">' . PHP_VERSION . '</strong> <small>(SAPI: <strong>' . php_sapi_name() . '</strong>)</small></li>';
    
                //PHP memory limit
                echo '<li><i class="fa-solid fa-fw fa-memory"></i> PHP Memory Limit: <strong>' . ini_get('memory_limit') . '</strong></li>';
    
                //Persistent Object Caching (memcached)
                $memcached_enabled = ( extension_loaded('memcached') )? 'Enabled' : 'Disabled';
                echo '<li><i class="fa-solid fa-fw fa-box"></i> PHP Memcached: <strong>' . $memcached_enabled . '</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="fa-solid fa-code"></i> Parent theme directory size: <strong>' . $this->format_bytes($nebula_parent_size, 1) . '</strong> </li>';
                    echo '<li><i class="fa-solid 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="fa-solid 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="fa-solid 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="fa-solid 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>';
                }
    
                //Link to Query Monitor Environment Panel
                //if ( is_plugin_active('query-monitor/query-monitor.php') ){
                    //echo '<li><i class="fa-solid fa-fw fa-table"></i> <a href="#qm-environment">Additional Server Information <small>(Query Monitor)</small></a></li>'; //Not currently possible: https://github.com/johnbillion/query-monitor/issues/622
                //}
    
                //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="fa-regular fa-fw fa-file-alt"></i> <a href="' . $log_file['shortpath'] . '" target="_blank"><code title="' . $log_file['shortpath'] . '" style="cursor: help;">' . $log_file['name'] . '</code></a> 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="fa-solid 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="fa-solid 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="fa-solid 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="fa-regular fa-fw fa-calendar"></i> Installed: ' . initial_install_date() . '</li>';
    
                $latest_file = $this->last_modified();
                echo '<li><i class="fa-regular 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="fa-brands 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 '<li><i class="fa-brands fa-fw fa-wordpress"></i> <a href="site-health.php?tab=debug">WP Site Info &raquo;</a></li>'; //Link to WP Health Check Info page
    
                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>';
                }
    
                //Must-Use Plugins (if any exist)
                if ( is_dir(WPMU_PLUGIN_DIR) && is_array(scandir(WPMU_PLUGIN_DIR)) ){
                    $directory_search_options['mu_plugins'] = '<option value="mu_plugins">Must-Use Plugins</option>';
                }
    
                //Add active plugins to search list
                $directory_search_options['all_plugins'] = '<option value="all_plugins">All Plugins</option>';
                $all_plugins = get_plugins();
                foreach ( $all_plugins as $plugin => $plugin_data ){
                    $plugin_name = $plugin_data['Name'];
                    $safe_plugin_name = str_replace(array(' ', '-', '/'), '_', strtolower($plugin_name));
                    $inactive_indicator = ( is_plugin_active($plugin) )? '' : ' (Inactive)';
                    $directory_search_options[$safe_plugin_name] = '<option value="' . $safe_plugin_name . '">' . $plugin_name . $inactive_indicator . '</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="fa-solid fa-fw fa-magnifying-glass"></i> <input class="findterm" type="text" placeholder="Search files" autocorrect="off" autocapitalize="off" spellcheck="false" /><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?