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

    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_class = '';
                $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_class = 'text-caution'; //Warning (orange)
                        $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_class = 'text-danger'; //Danger (red)
                        $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: <a class="' . $php_version_class . '" href="https://www.php.net/supported-versions.php" target="_blank" rel="noopener noreferrer" style="cursor: ' . $php_version_cursor . ';" title="' . $php_version_info . '"><strong>' . PHP_VERSION . '</strong></a> <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 or Redis)
                $memory_cache_enabled = '<strong>Disabled</strong>';
                if ( extension_loaded('memcached') ){
                    $memory_cache_enabled = '<strong>Memcached</strong>';
                } elseif ( extension_loaded('redis') ){
                    $memory_cache_enabled = '<strong>Redis</strong>';
                }
                echo '<li><i class="fa-solid fa-fw fa-box"></i> Memory Cache: ' . $memory_cache_enabled . '</li>';
    
                //Bytecode Caching aka Opcode Cache (Zend Opcache)
                $opcode_cache_enabled = ( extension_loaded('Zend OPcache') )? '<strong>Zend OPcache</strong>' : '<strong class="highlight-bad">Disabled</strong>';
                echo '<li><i class="fa-solid fa-fw fa-box"></i> Opcode Cache: ' . $opcode_cache_enabled . '</li>';
    
                //Count total WordPress updates available
                require_once ABSPATH . 'wp-admin/includes/update.php';
                $update_data = wp_get_update_data();
                $updates_count = $update_data['counts']['total'];
                if ( $updates_count > 0 ){
                    $updates_class = '';
    
                    if ( $updates_count > 10 ){ //If there are many updates available
                        $updates_class = 'text-danger"';
                    }
    
                    $updates_count = '<a class="' . $updates_class . '" href="update-core.php">' . $updates_count . ' &raquo;</a>';
                    echo '<li><i class="fa-regular fa-fw fa-circle-up"></i> Updates Available: <strong>' . $updates_count . '</strong></li>';
                }
    
                //Check SMTP mail status
                $smtp_status = $this->check_smtp_status();
                $smtp_status_output = ''; //Empty unless there is a problem
                if ( strpos(strtolower($smtp_status), 'error') != false ){
                    $smtp_status_output = '<strong class="text-danger"><i class="fa-solid fa-fw fa-exclamation-triangle"></i> ' . $smtp_status . '</strong>';
                } elseif ( strtolower($smtp_status) == 'unknown' ){
                    $smtp_status_output = '<em class="text-caution">Unable to Check</em>';
                }
                if ( !empty($smtp_status_output) ){
                    echo '<li><i class="fa-solid fa-fw fa-envelope"></i> SMTP Status: ' . $smtp_status_output . '</li>';
                }
    
                //Count 404s if the Redirection plugin is being used
                if ( is_plugin_active('redirection/redirection.php') ){
                    $count_of_404s = $this->transient('redirection_404_count', function(){
                        global $wpdb;
    
                        //Count the rows in PHP (instead of MySQL) to avoid processing the entire DB table
                        $results = $wpdb->get_col($wpdb->prepare(
                            'SELECT http_code FROM ' . $wpdb->prefix . 'redirection_404
                            WHERE http_code = 404
                            AND created >= %s
                            LIMIT 1000',
                            date('Y-m-d H:i:s', strtotime('-24 hours'))
                        ));
    
                        return count($results);
                    }, HOUR_IN_SECONDS);
    
                    if ( !empty($count_of_404s) ){ //Only show when they exist (this also prevents showing null if something is wrong with the query)
                        if ( $count_of_404s >= 999 ){ //If we reached the limit above, assume there are more that weren't counted
                            $count_of_404s = '<span class="text-danger"><i class="fa-solid fa-fw fa-exclamation-triangle"></i> 1000+</span>';
                        } elseif ( $count_of_404s >= 500 ){
                            $count_of_404s = '<span class="text-caution">' . $count_of_404s . '</span>';
                        }
    
                        echo '<li><i class="fa-regular fa-fw fa-file-excel"></i> 404s: <strong><a href="tools.php?page=redirection.php&sub=404s&groupby=url">' . $count_of_404s . '</a></strong> <small>(Last 24 hours)</small></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>';
                }
    
                //Plugins directory size (and count)
                $plugins_size = nebula()->transient('nebula_directory_size_plugins', function(){
                    $plugins_dir = WP_CONTENT_DIR . '/plugins';
                    return $this->foldersize($plugins_dir);
                }, HOUR_IN_SECONDS*36);
                $all_plugins = nebula()->transient('nebula_count_plugins', function(){
                    return get_plugins();
                }, WEEK_IN_SECONDS);
                $active_plugins = get_option('active_plugins', array());
                echo '<li><i class="fa-solid fa-plug"></i> Plugins directory size: <strong>' . $this->format_bytes($plugins_size, 1) . '</strong> <small>(' . count($active_plugins) . ' active of ' . count($all_plugins) . ' installed)</small></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);
    
                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);
    
                    if ( !empty($disk_total_space) ){ //Ignore when this results in 0 bytes total
                        $disk_space_percent_used = round((($disk_total_space-$disk_free_space)/$disk_total_space)*100);
    
                        $disk_usage_class = '';
                        if ( $disk_free_space/GB_IN_BYTES < 10 || $disk_space_percent_used > 75 ){
                            $disk_usage_class = 'text-caution'; //Warning
    
                            if ( $disk_free_space/GB_IN_BYTES < 5 || $disk_space_percent_used > 90 ){
                                $disk_usage_class = 'text-danger'; //Danger
                            }
                        }
    
                        echo '<li><i class="fa-solid fa-fw fa-hdd"></i> Disk Space Available: <strong class="' . $disk_usage_class . '">' . $this->format_bytes($disk_free_space, 1) . '</strong> <small class="' . $disk_usage_class . '">(Using ' . $disk_space_percent_used . '% of <strong>' . $this->format_bytes($disk_total_space) . '</strong> total)</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 ){
                        if ( !empty($log_file['bytes']) && $log_file['bytes'] > 999 ){ //Only show the file if it has a size and is at least 1kb
                            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>';
                        }
                    }
                }
    
                //Fatal error count
                $fatal_error_count = $this->transient('fatal_error_count', function(){
                    return $this->count_fatal_errors();
                }, HOUR_IN_SECONDS);
    
                if ( !empty($fatal_error_count) ){
                    $fatal_error_count_description = '';
    
                    if ( intval($fatal_error_count) ){ //If the result is a number (not a string which represents a problem)
                        $fatal_error_count_description = ' <small>(last 7 days)</small>';
                    }
    
                    echo '<li class="text-danger"><i class="fa-solid fa-fw fa-bug"></i> Fatal Errors: <strong><a class="text-danger" href="' . ini_get('error_log') . '" target="_blank">' . $fatal_error_count . '</a></strong>' . $fatal_error_count_description . '</li>'; //The <a> tag is just to show the location of the error log file
                }
    
                //Service Worker
                if ( $this->get_option('service_worker') ){
                    if ( !is_ssl() ){
                        echo '<li><i class="fa-solid fa-fw fa-microchip" class="text-danger"></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" class="text-danger"></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?