Changeset 3203857
- Timestamp:
- 12/06/2024 08:30:40 PM (15 months ago)
- Location:
- wp-settings/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (1 diff)
-
wp-settings.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-settings/trunk/readme.txt
r3202695 r3203857 1 1 === WP Settings:WordPress Settings and Database Backup === 2 2 Contributors: codecompiled 3 Tags: View WordPress Settings,WP Settings,Server details,View Database,Generate Database Backup Script,View all the Installed Plugins3 Tags: WordPress Settings,Theme Settings,DB Backup,Server details,Plugin details 4 4 Plugin Name: WP Settings 5 5 Tested up to: 6.7 -
wp-settings/trunk/wp-settings.php
r3203292 r3203857 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.5. 16 Version: 2.5.2 7 7 Author: CodeCompiled 8 8 Author URI: http://www.codecompiled.com … … 29 29 // Define tabs 30 30 $tabs = [ 31 'homepage' => 'Site Settings',32 'databse' => 'Database Settings'31 'homepage' => 'Site details', 32 'databse' => 'Database details' 33 33 ]; 34 34 … … 90 90 add_action('wp_print_scripts', 'wpsettings_load_scripts_styles'); 91 91 92 function wpsettings_getMySqlDetails( ) {92 function wpsettings_getMySqlDetails($topN = 20) { 93 93 global $wpdb; 94 94 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 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 106 98 $ws_mysqldetails = array(); 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 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 ) 149 121 ); 150 } 151 152 // Assign the top 5 tables as rows to TABLE DETAILS 153 $ws_mysqldetails["TABLE DETAILS"] = $tableDetails; 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 all tables for filtering 136 $allTables = $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 $tableSchema 144 ) 145 ); 146 147 // Sort tables by size in descending order 148 usort($allTables, function ($a, $b) { 149 return floatval($b->TableSizeMB) - floatval($a->TableSizeMB); 150 }); 151 152 // Slice top N rows 153 $topTables = array_slice($allTables, 0, $topN); 154 155 // Handle empty or null results gracefully 156 $tableDetails = array(); 157 if (!empty($topTables)) { 158 foreach ($topTables as $table) { 159 $tableDetails[] = array( 160 "Table Name" => $table->TableName ?? 'Unknown', 161 "Size (MB)" => $table->TableSizeMB !== null ? $table->TableSizeMB : 'Unknown', 162 "Rows" => $table->TableRows !== null ? $table->TableRows : 'Unknown' 163 ); 164 } 165 } else { 166 $tableDetails[] = array( 167 "Table Name" => 'No Data', 168 "Size (MB)" => 'No Data', 169 "Rows" => 'No Data' 170 ); 171 } 172 173 // Assign the table details to the result 174 $ws_mysqldetails["TABLE DETAILS"] = $tableDetails; 175 176 } catch (Exception $e) { 177 // Handle exceptions by providing default values and optionally logging errors 178 error_log('Error fetching MySQL details: ' . $e->getMessage()); 179 $ws_mysqldetails = array( 180 "VERSION" => "Unknown", 181 "DATABASE NAME" => "Unknown", 182 "DATABASE USER NAME" => "Unknown", 183 "DATABASE HOST" => "Unknown", 184 "DATABASE SIZE (MB)" => "Unknown", 185 "NO. OF TABLES" => "Unknown", 186 "TABLE DETAILS" => array( 187 array( 188 "Table Name" => "No Data", 189 "Size (MB)" => "No Data", 190 "Rows" => "No Data" 191 ) 192 ) 193 ); 194 } 154 195 155 196 return $ws_mysqldetails; 156 197 } 198 199 157 200 function wpsettings_bloginfo_array() { 158 201 $fields = array('name', 'description', 'wpurl', 'url', 'admin_email', 'version','categories','pages','pingback_url', 'language'); … … 318 361 319 362 <?php 320 if(isset($_POST["names"])) 321 { 322 backup_tables(); 323 } 324 else 325 { 326 getDatabaseContent(); 327 } 363 364 if (isset($_REQUEST['update'])) { 365 if ($_REQUEST['update'] === 'download') { 366 // Action for the "Download" button 367 backup_tables(); 368 } //elseif ($_REQUEST['update'] === 'update') { 369 // Action for the "Update" button: Display top N rows filtered by size 370 //getDatabaseContent(); // Use the method that calls wpsettings_getMySqlDetails 371 // } 372 373 374 } 375 getDatabaseContent(); 376 328 377 ?> 329 378 … … 353 402 354 403 function getDatabaseContent() { 404 // Initialize default number of tables 405 $topN = isset($_POST['top_n']) ? intval($_POST['top_n']) : 20; // Default to 20 tables if no selection 406 $topN = ($topN > 0 && $topN <= 100) ? $topN : 20; // Ensure valid range (1-100) 407 355 408 ?> 356 <form action="" method="POST" >409 <form action="" method="POST" id="dbContentForm"> 357 410 <table class="headerInfo" style="border-collapse: collapse; width: 100%; border: 1px solid #ccc;"> 358 411 <tr> … … 362 415 </tr> 363 416 <?php 364 $sqldetails = wpsettings_getMySqlDetails( );417 $sqldetails = wpsettings_getMySqlDetails($topN); 365 418 366 // Loop through generaldetails419 // Display general database details 367 420 foreach ($sqldetails as $sqlKey => $sqlValue) { 368 421 if ($sqlKey !== "TABLE DETAILS") { // Exclude table details for now 369 422 ?> 370 423 <tr> 371 <td style="width: 30%; background-color: #f9f9f9;"><?php echo $sqlKey; ?></td>372 <td><?php echo is_array($sqlValue) ? implode(', ', $sqlValue) : $sqlValue; ?></td>424 <td style="width: 30%; background-color: #f9f9f9;"><?php echo htmlspecialchars($sqlKey); ?></td> 425 <td><?php echo is_array($sqlValue) ? implode(', ', $sqlValue) : htmlspecialchars($sqlValue); ?></td> 373 426 </tr> 374 427 <?php … … 380 433 <tr> 381 434 <td colspan="5" style="text-align: left; padding: 10px; font-weight: bold; background-color: #0073aa; color: #fff;"> 382 Tables (sorted by size,top 20):435 Tables (sorted by size, top <?php echo $topN; ?>): 383 436 </td> 384 437 </tr> … … 390 443 <?php 391 444 if (isset($sqldetails["TABLE DETAILS"]) && is_array($sqldetails["TABLE DETAILS"])) { 392 foreach ($sqldetails["TABLE DETAILS"] as $tableDetail) { 393 ?> 445 foreach ($sqldetails["TABLE DETAILS"] as $tableDetail) { ?> 446 <tr> 447 <td style="background-color: #fff;"><?php echo htmlspecialchars($tableDetail["Table Name"]); ?></td> 448 <td style="background-color: #fff;"><?php echo htmlspecialchars($tableDetail["Size (MB)"]); ?></td> 449 <td style="background-color: #fff;"><?php echo htmlspecialchars($tableDetail["Rows"]); ?></td> 450 </tr> 451 <?php 452 } 453 } else { 454 ?> 394 455 <tr> 395 <td style="background-color: #fff;"><?php echo $tableDetail["Table Name"]; ?></td> 396 <td style="background-color: #fff;"><?php echo $tableDetail["Size (MB)"]; ?></td> 397 <td style="background-color: #fff;"><?php echo $tableDetail["Rows"]; ?></td> 456 <td colspan="3" style="text-align: center; color: red;">No table details found or an error occurred.</td> 398 457 </tr> 399 <?php 400 } 458 <?php 401 459 } 402 460 ?> … … 404 462 <tr> 405 463 <td colspan="5" style="text-align: left; padding: 10px;"> 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;"> 464 <!-- Dropdown for selecting number of tables --> 465 Display top 466 <select name="top_n" id="topNSelect" style="margin-right: 10px;"> 467 <?php for ($i = 5; $i <= 100; $i += 5) { ?> 468 <option value="<?php echo $i; ?>" <?php echo ($topN == $i) ? 'selected' : ''; ?>> 469 <?php echo $i; ?> 470 </option> 471 <?php } ?> 472 </select> 473 tables 474 475 <!-- Update button --> 476 <!-- <button type="button" name="action" value="update" style="padding: 5px 15px; background-color: #28a745; color: #fff; border: none; cursor: pointer;"> 477 Update 478 </button> --> 479 <button type="submit" value="update" name="update" style="padding: 5px 15px; background-color: #28a745; color: #fff; border: none; cursor: pointer;"> 480 Update 481 </button> 482 483 <!-- Download button --> 484 <!-- <button type="button" onclick="setNamesAndSubmit();" id="names" value="names" style="margin-left: 10px; padding: 5px 15px; background-color: #0073aa; color: #fff; border: none; cursor: pointer;"> 485 Download 486 </button> --> 487 <button type="submit" value="download" name="update" style="margin-left: 10px; padding: 5px 15px; background-color: #0073aa; color: #fff; border: none; cursor: pointer;"> 488 Download 489 </button> 408 490 </td> 409 491 </tr> 410 492 </table> 411 <input type="hidden" name="names" id="names"> 493 <input type="hidden" name="names" id="names" value=""> 494 <input type="hidden" name="action" id="action" value=""> 412 495 </form> 413 496 <?php 414 497 } 498 499 500 501 415 502 416 503
Note: See TracChangeset
for help on using the changeset viewer.