'version_info_admin_bar', 'title' => $this->get_version_string(), 'parent' => 'top-secondary', ); $nodes['version_info_copy_md'] = array( 'id' => 'version_info_copy_md', 'parent' => 'version_info_admin_bar', 'title' => __( 'Copy as Markdown', 'version-info' ), 'href' => '#', ); } /** * Filtered admin-bar node definitions. * * @var array $nodes */ $nodes = apply_filters( 'version_info_admin_bar_nodes', $nodes ); foreach ( $nodes as $node ) { $wp_admin_bar->add_node( $node ); } } /** * Builds the admin-bar version summary string. */ private function get_version_string() { global $wpdb; $wp_version = apply_filters( 'version_info_wp_version', get_bloginfo( 'version' ) ); $php_version = apply_filters( 'version_info_php_version', phpversion() ); $server_software = apply_filters( 'version_info_server_software', sanitize_text_field( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : __( 'Unknown', 'version-info' ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- reading the MySQL server version; no WP API exists and the value is not site data. $mysql_version = apply_filters( 'version_info_mysql_version', (string) $wpdb->get_var( 'SELECT VERSION()' ) ); $details = sprintf( /* translators: %1$s: WP version, %2$s: PHP version, %3$s: server software, %4$s: MySQL version */ __( 'WordPress %1$s | PHP %2$s | Web Server %3$s | MySQL %4$s', 'version-info' ), esc_html( $wp_version ), esc_html( $php_version ), esc_html( $server_software ), esc_html( $mysql_version ) ); if ( get_option( 'version_info_show_memory', true ) ) { $memory_text = SystemInfo::memory_text(); if ( '' !== $memory_text ) { /* translators: %s: PHP memory usage summary, e.g. "24.6 MB of 256 MB (9.6%)" */ $details .= sprintf( __( ' | Mem %s', 'version-info' ), esc_html( $memory_text ) ); } } $eol_alert = SystemInfo::php_eol_alert_text(); if ( '' !== $eol_alert ) { $details .= ' | ' . esc_html( $eol_alert ); } return $details; } /** * Clipboard handler for the "Copy as Markdown" control (admin-bar node * and dashboard-widget button). Inline vanilla JS — the plugin enqueues * no assets by design; see the General-tab script for the precedent. */ public function print_copy_js() { if ( ! Plugin::current_user_can_view() || ( ! get_option( 'version_info_show_admin_bar', false ) && ! get_option( 'version_info_show_dashboard_widget', false ) ) ) { return; } if ( ! is_admin() && ! is_admin_bar_showing() ) { return; } // JSON with hex flags makes `` breakout impossible and keeps // multi-line payloads intact (esc_js() would mangle the newlines). $json = wp_json_encode( SystemInfo::markdown_table(), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ); if ( false === $json ) { // Bad UTF-8 somewhere in the payload — the control becomes a no-op. return; } ?>