Changeset 3203292
- Timestamp:
- 12/05/2024 09:47:20 PM (15 months ago)
- File:
-
- 1 edited
-
wp-settings/trunk/wp-settings.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-settings/trunk/wp-settings.php
r3203290 r3203292 4 4 Plugin URI: https://wordpress.org/plugins/wp-settings/ 5 5 Description:Displays the important information about WordPress installation such as important wordpress settings,database settings,theme details and php information.You can generate DB Backup Script for restoring the database and for keeping database backups. 6 Version: 2. 66 Version: 2.5.1 7 7 Author: CodeCompiled 8 8 Author URI: http://www.codecompiled.com … … 90 90 add_action('wp_print_scripts', 'wpsettings_load_scripts_styles'); 91 91 92 function wpsettings_getMySqlDetails( $topN = 20) {92 function wpsettings_getMySqlDetails() { 93 93 global $wpdb; 94 94 95 // Ensure $topN is a positive integer and within a reasonable range 96 $topN = (is_numeric($topN) && $topN > 0 && $topN <= 100) ? intval($topN) : 20; 97 95 // Query for MySQL version 96 $results = $wpdb->get_results('SELECT VERSION() as mysqlversion'); 97 $sqlInfoVer = ''; 98 foreach ($results as $result) { 99 $sqlInfoVer = $result->mysqlversion; 100 } 101 102 // Table schema name (DB_NAME) for information_schema queries 103 $tableSchema = DB_NAME; 104 105 // Fetching MySQL details 98 106 $ws_mysqldetails = array(); 99 100 try { 101 // Query for MySQL version 102 $results = $wpdb->get_results('SELECT VERSION() as mysqlversion'); 103 $ws_mysqldetails["VERSION"] = $results[0]->mysqlversion ?? 'Unknown'; 104 105 // Set the database schema (DB_NAME) for queries 106 $tableSchema = DB_NAME; 107 108 // Basic database details 109 $ws_mysqldetails["DATABASE NAME"] = DB_NAME ?: 'Not Set'; 110 $ws_mysqldetails["DATABASE USER NAME"] = DB_USER ?: 'Not Set'; 111 $ws_mysqldetails["DATABASE HOST"] = DB_HOST ?: 'Not Set'; 112 113 // Fetch database size in MB 114 $dbSize = $wpdb->get_var( 115 $wpdb->prepare( 116 "SELECT SUM(data_length + index_length) / 1024 / 1024 AS dbsize 117 FROM information_schema.TABLES 118 WHERE table_schema = %s", 119 $tableSchema 120 ) 107 $ws_mysqldetails["VERSION"] = $sqlInfoVer; 108 $ws_mysqldetails["DATABASE NAME"] = DB_NAME; 109 $ws_mysqldetails["DATABASE USER NAME"] = DB_USER; 110 $ws_mysqldetails["DATABASE HOST"] = DB_HOST; 111 $ws_mysqldetails["DATABASE SIZE (MB)"] = $wpdb->get_var( 112 $wpdb->prepare( 113 "SELECT SUM(data_length + index_length) / 1024 / 1024 AS dbsize 114 FROM information_schema.TABLES 115 WHERE table_schema = %s", 116 $tableSchema 117 ) 118 ); 119 $ws_mysqldetails["NO. OF TABLES"] = $wpdb->get_var( 120 $wpdb->prepare( 121 "SELECT COUNT(*) 122 FROM information_schema.TABLES 123 WHERE table_schema = %s", 124 $tableSchema 125 ) 126 ); 127 128 // Fetching top 5 largest tables by size and their row counts 129 $topTables = $wpdb->get_results( 130 $wpdb->prepare( 131 "SELECT table_name AS TableName, 132 ROUND((data_length + index_length) / 1024 / 1024, 2) AS TableSizeMB, 133 table_rows AS TableRows 134 FROM information_schema.TABLES 135 WHERE table_schema = %s 136 ORDER BY TableSizeMB DESC 137 LIMIT 20", 138 $tableSchema 139 ) 140 ); 141 142 // Prepare rows with table name, size, and row count 143 $tableDetails = array(); 144 foreach ($topTables as $table) { 145 $tableDetails[] = array( 146 "Table Name" => $table->TableName, 147 "Size (MB)" => $table->TableSizeMB, 148 "Rows" => $table->TableRows 121 149 ); 122 $ws_mysqldetails["DATABASE SIZE (MB)"] = $dbSize !== null ? round($dbSize, 2) : 'Unknown'; 123 124 // Fetch the total number of tables 125 $tableCount = $wpdb->get_var( 126 $wpdb->prepare( 127 "SELECT COUNT(*) 128 FROM information_schema.TABLES 129 WHERE table_schema = %s", 130 $tableSchema 131 ) 132 ); 133 $ws_mysqldetails["NO. OF TABLES"] = $tableCount !== null ? intval($tableCount) : 'Unknown'; 134 135 // Fetch top N largest tables by size 136 $topTables = $wpdb->get_results( 137 $wpdb->prepare( 138 "SELECT table_name AS TableName, 139 ROUND((data_length + index_length) / 1024 / 1024, 2) AS TableSizeMB, 140 table_rows AS TableRows 141 FROM information_schema.TABLES 142 WHERE table_schema = %s 143 ORDER BY TableSizeMB DESC 144 LIMIT %d", 145 $tableSchema, 146 $topN 147 ) 148 ); 149 150 // Handle empty or null results gracefully 151 $tableDetails = array(); 152 if (!empty($topTables)) { 153 foreach ($topTables as $table) { 154 $tableDetails[] = array( 155 "Table Name" => $table->TableName ?? 'Unknown', 156 "Size (MB)" => $table->TableSizeMB !== null ? $table->TableSizeMB : 'Unknown', 157 "Rows" => $table->TableRows !== null ? $table->TableRows : 'Unknown' 158 ); 159 } 160 } else { 161 $tableDetails[] = array( 162 "Table Name" => 'No Data', 163 "Size (MB)" => 'No Data', 164 "Rows" => 'No Data' 165 ); 166 } 167 168 // Assign the table details to the result 169 $ws_mysqldetails["TABLE DETAILS"] = $tableDetails; 170 171 } catch (Exception $e) { 172 // Handle exceptions by providing default values and optionally logging errors 173 error_log('Error fetching MySQL details: ' . $e->getMessage()); 174 $ws_mysqldetails = array( 175 "VERSION" => "Unknown", 176 "DATABASE NAME" => "Unknown", 177 "DATABASE USER NAME" => "Unknown", 178 "DATABASE HOST" => "Unknown", 179 "DATABASE SIZE (MB)" => "Unknown", 180 "NO. OF TABLES" => "Unknown", 181 "TABLE DETAILS" => array( 182 array( 183 "Table Name" => "No Data", 184 "Size (MB)" => "No Data", 185 "Rows" => "No Data" 186 ) 187 ) 188 ); 189 } 150 } 151 152 // Assign the top 5 tables as rows to TABLE DETAILS 153 $ws_mysqldetails["TABLE DETAILS"] = $tableDetails; 190 154 191 155 return $ws_mysqldetails; 192 156 } 193 194 157 function wpsettings_bloginfo_array() { 195 158 $fields = array('name', 'description', 'wpurl', 'url', 'admin_email', 'version','categories','pages','pingback_url', 'language'); … … 390 353 391 354 function getDatabaseContent() { 392 // Check which action was triggered393 $action = isset($_POST['action']) ? sanitize_text_field($_POST['action']) : '';394 $topN = 20; // Default value for top tables395 396 if ($action === 'update') {397 // Handle "Update" button action398 $topN = isset($_POST['top_n']) ? intval($_POST['top_n']) : 20;399 $topN = ($topN > 0) ? $topN : 20; // Fallback to 20 if invalid value provided400 } elseif ($action === 'download') {401 // Handle "Download" button action402 handleDatabaseDownload(); // Call a function to handle the download (separate logic for clarity)403 return; // Stop further execution after download404 }405 406 // Fetch database details with the specified top N407 $sqldetails = wpsettings_getMySqlDetails($topN);408 355 ?> 409 356 <form action="" method="POST"> … … 415 362 </tr> 416 363 <?php 417 // Display general database details 364 $sqldetails = wpsettings_getMySqlDetails(); 365 366 // Loop through general details 418 367 foreach ($sqldetails as $sqlKey => $sqlValue) { 419 368 if ($sqlKey !== "TABLE DETAILS") { // Exclude table details for now … … 431 380 <tr> 432 381 <td colspan="5" style="text-align: left; padding: 10px; font-weight: bold; background-color: #0073aa; color: #fff;"> 433 Tables (sorted by size, top <?php echo $topN; ?>):382 Tables(sorted by size,top 20): 434 383 </td> 435 384 </tr> … … 455 404 <tr> 456 405 <td colspan="5" style="text-align: left; padding: 10px;"> 457 <!-- "Download" Button --> 458 <input type="submit" name="action" value="download" style="margin-right: 20px; padding: 5px 15px; background-color: #0073aa; color: #fff; border: none; cursor: pointer;"> 459 460 <!-- Dropdown and "Update" Button --> 461 Display top 462 <select name="top_n" style="margin-right: 10px;"> 463 <option value="5" <?php echo ($topN == 5) ? 'selected' : ''; ?>>5</option> 464 <option value="10" <?php echo ($topN == 10) ? 'selected' : ''; ?>>10</option> 465 <option value="20" <?php echo ($topN == 20) ? 'selected' : ''; ?>>20</option> 466 <option value="50" <?php echo ($topN == 50) ? 'selected' : ''; ?>>50</option> 467 </select> 468 tables 469 <input type="submit" name="action" value="update" style="padding: 5px 15px; background-color: #28a745; color: #fff; border: none; cursor: pointer;"> 406 Click the download button to take a backup of the database 407 <input type="submit" value="Download" name="submit_btn" style="margin-left: 10px; padding: 5px 15px; background-color: #0073aa; color: #fff; border: none; cursor: pointer;"> 470 408 </td> 471 409 </tr> 472 410 </table> 411 <input type="hidden" name="names" id="names"> 473 412 </form> 474 413 <?php 475 414 } 476 477 /**478 * Handles database download functionality.479 */480 function handleDatabaseDownload() {481 // Logic to generate and serve the database backup file482 // Example placeholder (replace with actual backup generation code):483 header('Content-Type: application/sql');484 header('Content-Disposition: attachment; filename="database_backup.sql"');485 echo "-- Database backup content here --";486 exit;487 }488 489 490 415 491 416
Note: See TracChangeset
for help on using the changeset viewer.