<br /> <h4> <?php if (isset($_POST["optimize-db"])) { list($part1, $part2) = wpo_getCurrentDBSize(); _e('Current database size:', 'wp-optimize'); echo ' '; echo '<font color="blue">'; echo $part1 . '</font> '; echo ' <br />'; _e('You have saved:', 'wp-optimize'); echo ' '; echo '<font color="blue">'; echo $part2 . '</font> '; } else { list($part1, $part2) = wpo_getCurrentDBSize(); _e('Current database size:', 'wp-optimize'); echo ' '; echo '<font color="blue">'; echo $part1 . '</font> '; $this_value = $part2; if ($this_value > 0) { echo ' <br />'; _e('You can save almost:', 'wp-optimize'); echo ' '; echo '<font color="red">'; echo $part2 . '</font> '; } } ?> </h4>
function wpo_cron_action() { global $wpdb; list($retention_enabled, $retention_period) = wpo_getRetainInfo(); wpo_debugLog('Starting wpo_cron_action()'); if (get_option(OPTION_NAME_SCHEDULE) == 'true') { $this_options = get_option('wp-optimize-auto'); // revisions if ($this_options['revisions'] == 'true') { $clean = "DELETE FROM `{$wpdb->posts}` WHERE post_type = 'revision'"; if ($retention_enabled == 'true') { $clean .= ' and post_modified < NOW() - INTERVAL ' . $retention_period . ' WEEK'; } $clean .= ';'; $revisions = $wpdb->query($clean); } // auto drafts if ($this_options['drafts'] == 'true') { $clean = "DELETE FROM `{$wpdb->posts}` WHERE post_status = 'auto-draft'"; if ($retention_enabled == 'true') { $clean .= ' and post_modified < NOW() - INTERVAL ' . $retention_period . ' WEEK'; } $clean .= ';'; $autodraft = $wpdb->query($clean); // trash posts // TODO: query trashed posts and cleanup metadata $clean = "DELETE FROM `{$wpdb->posts}` WHERE post_status = 'trash'"; if ($retention_enabled == 'true') { $clean .= ' and post_modified < NOW() - INTERVAL ' . $retention_period . ' WEEK'; } $clean .= ';'; $posttrash = $wpdb->query($clean); } // spam comments if ($this_options['spams'] == 'true') { $clean = "DELETE FROM `{$wpdb->comments}` WHERE comment_approved = 'spam'"; if ($retention_enabled == 'true') { $clean .= ' and comment_date < NOW() - INTERVAL ' . $retention_period . ' WEEK'; } $clean .= ';'; $comments = $wpdb->query($clean); // trashed comments // TODO: query trashed comments and cleanup metadata $clean = "DELETE FROM `{$wpdb->comments}` WHERE comment_approved = 'trash'"; if ($retention_enabled == 'true') { $clean .= ' and comment_date < NOW() - INTERVAL ' . $retention_period . ' WEEK'; } $clean .= ';'; $commentstrash = $wpdb->query($clean); // TODO: still need to test now cleaning up comments meta tables $clean = "DELETE FROM `{$wpdb->commentmeta}` WHERE comment_id NOT IN ( SELECT comment_id FROM `{$wpdb->comments}` )"; $clean .= ';'; $commentstrash1 = $wpdb->query($clean); // TODO: still need to test now cleaning up comments meta tables - removing akismet related settings $clean = "DELETE FROM `{$wpdb->commentmeta}` WHERE meta_key LIKE '%akismet%'"; $clean .= ';'; $commentstrash2 = $wpdb->query($clean); } // transient options if ($this_options['transient'] == 'true') { $clean = "DELETE FROM `{$wpdb->options}` WHERE option_name LIKE '_transient_%' OR option_name LIKE '_site_transient_%'"; $clean .= ';'; $transient_options = $wpdb->query($clean); } // postmeta // TODO: refactor this with proper query if ($this_options['postmeta'] == 'true') { $clean = "DELETE pm FROM `{$wpdb->postmeta}` pm LEFT JOIN `{$wpdb->posts}` wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL"; $clean .= ';'; //$postmeta = $wpdb->query( $clean ); } // unused tags if ($this_options['tags'] == 'true') { //$clean = "DELETE t,tt FROM `$wpdb->terms` t INNER JOIN `$wpdb->term_taxonomy` tt ON t.term_id=tt.term_id WHERE tt.taxonomy='post_tag' AND tt.count=0"; //$clean .= ';'; //$tags = $wpdb->query( $clean ); } //db optimize part - optimize if ($this_options['optimize'] == 'true') { $db_tables = $wpdb->get_results('SHOW TABLES', ARRAY_A); foreach ($db_tables as $table) { $t = array_values($table); $wpdb->query("OPTIMIZE TABLE `" . $t[0] . "`"); wpo_debugLog('optimizing .... ' . $t[0]); } ob_start(); list($part1, $part2) = wpo_getCurrentDBSize(); $thistime = current_time("timestamp", 0); $thedate = gmdate(get_option('date_format') . ' ' . get_option('time_format'), $thistime); update_option(OPTION_NAME_LAST_OPT, $thedate); wpo_updateTotalCleaned(strval($part2)); // Sending notification email if (get_option(OPTION_NAME_ENABLE_EMAIL) !== false) { //#TODO need to fix the problem with variable value not passing through if (get_option(OPTION_NAME_ENABLE_EMAIL_ADDRESS) !== '') { wpo_sendEmail($thedate, $part2); } } else { // } ob_end_flush(); } // endif $this_options['optimize'] } // end if ( get_option(OPTION_NAME_SCHEDULE) == 'true') }
function wpo_cron_action() { global $wpdb; list($retention_enabled, $retention_period) = wpo_getRetainInfo(); wpo_debugLog('Starting wpo_cron_action()'); if (get_option(OPTION_NAME_SCHEDULE) == 'true') { $this_options = get_option('wp-optimize-auto'); // revisions if ($this_options['revisions'] == 'true') { $clean = "DELETE FROM {$wpdb->posts} WHERE post_type = 'revision'"; if ($retention_enabled == 'true') { $clean .= ' and post_modified < NOW() - INTERVAL ' . $retention_period . ' WEEK'; } $clean .= ';'; $revisions = $wpdb->query($clean); } // auto drafts if ($this_options['drafts'] == 'true') { $clean = "DELETE FROM {$wpdb->posts} WHERE post_status = 'auto-draft'"; if ($retention_enabled == 'true') { $clean .= ' and post_modified < NOW() - INTERVAL ' . $retention_period . ' WEEK'; } $clean .= ';'; $autodraft = $wpdb->query($clean); // trash posts // TODO: query trashed posts and cleanup metadata $clean = "DELETE FROM {$wpdb->posts} WHERE post_status = 'trash'"; if ($retention_enabled == 'true') { $clean .= ' and post_modified < NOW() - INTERVAL ' . $retention_period . ' WEEK'; } $clean .= ';'; $posttrash = $wpdb->query($clean); } // spam comments if ($this_options['spams'] == 'true') { $clean = "DELETE FROM {$wpdb->comments} WHERE comment_approved = 'spam'"; if ($retention_enabled == 'true') { $clean .= ' and comment_date < NOW() - INTERVAL ' . $retention_period . ' WEEK'; } $clean .= ';'; $comments = $wpdb->query($clean); // trashed comments // TODO: query trashed comments and cleanup metadata $clean = "DELETE FROM {$wpdb->comments} WHERE comment_approved = 'trash'"; if ($retention_enabled == 'true') { $clean .= ' and comment_date < NOW() - INTERVAL ' . $retention_period . ' WEEK'; } $clean .= ';'; $commentstrash = $wpdb->query($clean); // TODO: still need to test now cleaning up comments meta tables // $clean = "DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN ( SELECT comment_id FROM $wpdb->comments )"; // $clean .= ';'; // $commentstrash1 = $wpdb->query( $clean ); // TODO: still need to test now cleaning up comments meta tables - removing akismet related settings // $clean = "DELETE FROM $wpdb->commentmeta WHERE meta_key LIKE '%akismet%'"; // $clean .= ';'; // $commentstrash2 = $wpdb->query( $clean ); } // transient options if ($this_options['transient'] == 'true') { $clean = "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_%' OR option_name LIKE '_site_transient_%'"; $clean .= ';'; $transient_options = $wpdb->query($clean); } // postmeta // TODO: refactor this with proper query if ($this_options['postmeta'] == 'true') { $clean = "DELETE pm FROM {$wpdb->postmeta} pm LEFT JOIN {$wpdb->posts} wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL"; $clean .= ';'; //$postmeta = $wpdb->query( $clean ); } // unused tags if ($this_options['tags'] == 'true') { //$clean = "DELETE t,tt FROM $wpdb->terms t INNER JOIN $wpdb->term_taxonomy tt ON t.term_id=tt.term_id WHERE tt.taxonomy='post_tag' AND tt.count=0"; //$clean .= ';'; //$tags = $wpdb->query( $clean ); } //db optimize part - optimize // disble optimization if innoDB if (WPO_TABLE_TYPE != 'innodb') { if ($this_options['optimize'] == 'true') { $db_tables = $wpdb->get_results('SHOW TABLES', ARRAY_A); foreach ($db_tables as $table) { $t = array_values($table); $wpdb->query("OPTIMIZE TABLE " . $t[0]); wpo_debugLog('optimizing .... ' . $t[0]); } //$dateformat = __('l jS \of F Y h:i:s A'); $dateformat = 'l jS \\of F Y h:i:s A'; $thisdate = date($dateformat); list($part1, $part2) = wpo_getCurrentDBSize(); update_option(OPTION_NAME_LAST_OPT, $thisdate); wpo_updateTotalCleaned(strval($part2)); wpo_debugLog('Updating options with value +' . $part2); } // endif $this_options['optimize'] } //end if if (WPO_TABLE_TYPE != 'innodb'){ } // end if ( get_option(OPTION_NAME_SCHEDULE) == 'true') }
function optimizeTables($Optimize = false) { ?> <h3> <?php _e('Database Name:', 'wp-optimize'); ?> '<?php _e(DB_NAME, 'wp-optimize'); echo "'"; ?> </h3> <?php if ($Optimize) { ?> <p><?php _e('Optimized all the tables found in the database.', 'wp-optimize'); ?> </p> <?php } ?> <br style="clear" /> <table class="widefat"> <thead> <tr> <th><?php _e('No.', 'wp-optimize'); ?> </th> <th><?php _e('Tables', 'wp-optimize'); ?> </th> <th><?php _e('Records', 'wp-optimize'); ?> </th> <th><?php _e('Data Size', 'wp-optimize'); ?> </th> <th><?php _e('Index Size', 'wp-optimize'); ?> </th> <th><?php _e('Type', 'wp-optimize'); ?> </th> <th><?php _e('Overhead', 'wp-optimize'); ?> </th> </tr> </thead> <tbody id="the-list"> <?php $alternate = ' class="alternate"'; global $wpdb; // Read SQL Version and act accordingly // Check for InnoDB tables // Check for windows servers $sqlversion = $wpdb->get_var("SELECT VERSION() AS version"); $total_gain = 0; $no = 0; $row_usage = 0; $data_usage = 0; $index_usage = 0; $overhead_usage = 0; $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS"); foreach ($tablesstatus as $tablestatus) { if ($no % 2 == 0) { $style = ''; } else { $style = ' class="alternate"'; } $no++; echo "<tr{$style}>\n"; echo '<td>' . number_format_i18n($no) . '</td>' . "\n"; echo "<td>{$tablestatus->Name}</td>\n"; echo '<td>' . number_format_i18n($tablestatus->Rows) . '</td>' . "\n"; echo '<td>' . wpo_format_size($tablestatus->Data_length) . '</td>' . "\n"; echo '<td>' . wpo_format_size($tablestatus->Index_length) . '</td>' . "\n"; echo '<td>' . $tablestatus->Engine . '</td>' . "\n"; //echo '<td>'.wpo_format_size($tablestatus->Data_free).'</td>'."\n"; if ($tablestatus->Engine != 'InnoDB') { echo '<td>'; if (isset($_POST["optimize-db"])) { if ($tablestatus->Data_free > 0) { echo '<font color="blue">'; echo wpo_format_size($tablestatus->Data_free); echo '</font>'; } else { echo '<font color="green">'; echo wpo_format_size($tablestatus->Data_free); echo '</font>'; } } else { if ($tablestatus->Data_free > 0) { echo '<font color="red">'; echo wpo_format_size($tablestatus->Data_free); echo '</font>'; } else { echo '<font color="green">'; echo wpo_format_size($tablestatus->Data_free); echo '</font>'; } } echo '</td>' . "\n"; } else { echo '<td>'; echo '<font color="blue">'; echo '-'; echo '</font>'; echo '</td>' . "\n"; } $row_usage += $tablestatus->Rows; $data_usage += $tablestatus->Data_length; $index_usage += $tablestatus->Index_length; if ($tablestatus->Engine != 'InnoDB') { $overhead_usage += $tablestatus->Data_free; $total_gain += $tablestatus->Data_free; } else { $overhead_usage += 0; $total_gain += 0; } echo '</tr>' . "\n"; } echo '<tr class="thead">' . "\n"; echo '<th>' . __('Total:', 'wp-optimize') . '</th>' . "\n"; echo '<th>' . sprintf(_n('%s Table', '%s Tables', $no, 'wp-optimize'), number_format_i18n($no)) . '</th>' . "\n"; echo '<th>' . sprintf(_n('%s Record', '%s Records', $row_usage, 'wp-optimize'), number_format_i18n($row_usage)) . '</th>' . "\n"; echo '<th>' . wpo_format_size($data_usage) . '</th>' . "\n"; echo '<th>' . wpo_format_size($index_usage) . '</th>' . "\n"; echo '<th>' . '-' . '</th>' . "\n"; echo '<th>'; if (isset($_POST["optimize-db"])) { if ($overhead_usage > 0) { echo '<font color="blue">'; echo wpo_format_size($overhead_usage); echo '</font>'; } else { echo '<font color="green">'; echo wpo_format_size($overhead_usage); echo '</font>'; } } else { if ($overhead_usage > 0) { echo '<font color="red">'; echo wpo_format_size($overhead_usage); echo '</font>'; } else { echo '<font color="green">'; echo wpo_format_size($overhead_usage); echo '</font>'; } } echo '</th>' . "\n"; echo '</tr>'; ?> </tbody> </table> <h3><?php _e('Total Size of Database', 'wp-optimize'); ?> :</h3> <h2><?php list($part1, $part2) = wpo_getCurrentDBSize(); echo $part1; ?> </h2> <?php if (isset($_POST["optimize-db"])) { ?> <?php //$total_gain = round ($total_gain,3); ?> <h3><?php _e('Optimization Results', 'wp-optimize'); ?> :</h3> <p style="color: #0000FF;"> <?php if ($total_gain > 0) { _e('Total Space Saved', 'wp-optimize'); echo ': '; echo wpo_format_size($total_gain); wpo_updateTotalCleaned(strval($total_gain)); } ?> </p> <?php } else { //$total_gain = round ($total_gain,3); ?> <?php if (!$total_gain == 0) { ?> <h3><?php if ($total_gain > 0) { _e('Optimization Possibility', 'wp-optimize'); echo ':'; } ?> </h3> <p style="color: #FF0000;"> <?php if ($total_gain > 0) { _e('Total space can be saved', 'wp-optimize'); ?> : <?php echo wpo_format_size($total_gain); } ?> </p> <?php } } ?> <?php }
function wpo_cron_action() { global $wpdb; list($retention_enabled, $retention_period) = wpo_getRetainInfo(); wpo_debugLog('Starting wpo_cron_action()'); if (get_option(OPTION_NAME_SCHEDULE) == 'true') { $this_options = get_option('wp-optimize-auto'); // revisions if ($this_options['revisions'] == 'true') { $clean = "DELETE FROM {$wpdb->posts} WHERE post_type = 'revision'"; if ($retention_enabled == 'true') { $clean .= ' and post_modified < NOW() - INTERVAL ' . $retention_period . ' WEEK'; } $clean .= ';'; $revisions = $wpdb->query($clean); } // auto drafts if ($this_options['drafts'] == 'true') { $clean = "DELETE FROM {$wpdb->posts} WHERE post_status = 'auto-draft'"; if ($retention_enabled == 'true') { $clean .= ' and post_modified < NOW() - INTERVAL ' . $retention_period . ' WEEK'; } $clean .= ';'; $autodraft = $wpdb->query($clean); // trash posts $clean = "DELETE FROM {$wpdb->posts} WHERE post_status = 'trash'"; if ($retention_enabled == 'true') { $clean .= ' and post_modified < NOW() - INTERVAL ' . $retention_period . ' WEEK'; } $clean .= ';'; $posttrash = $wpdb->query($clean); } // spam comments if ($this_options['spams'] == 'true') { $clean = "DELETE FROM {$wpdb->comments} WHERE comment_approved = 'spam'"; if ($retention_enabled == 'true') { $clean .= ' and comment_date < NOW() - INTERVAL ' . $retention_period . ' WEEK'; } $clean .= ';'; $comments = $wpdb->query($clean); // trashed comments $clean = "DELETE FROM {$wpdb->comments} WHERE comment_approved = 'post-trashed'"; if ($retention_enabled == 'true') { $clean .= ' and comment_date < NOW() - INTERVAL ' . $retention_period . ' WEEK'; } $clean .= ';'; $commentstrash = $wpdb->query($clean); } // transient options if ($this_options['transient'] == 'true') { $clean = "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_%' OR option_name LIKE '_site_transient_%'"; $clean .= ';'; $transient_options = $wpdb->query($clean); } // postmeta if ($this_options['postmeta'] == 'true') { $clean = "DELETE pm FROM {$wpdb->postmeta} pm LEFT JOIN {$wpdb->posts} wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL"; $clean .= ';'; $postmeta = $wpdb->query($clean); } // unused tags if ($this_options['tags'] == 'true') { $clean = "DELETE t,tt FROM {$wpdb->terms} t INNER JOIN {$wpdb->term_taxonomy} tt ON t.term_id=tt.term_id WHERE tt.taxonomy='post_tag' AND tt.count=0"; $clean .= ';'; $tags = $wpdb->query($clean); } //db optimize part - optimize if ($this_options['optimize'] == 'true') { $db_tables = $wpdb->get_results('SHOW TABLES', ARRAY_A); foreach ($db_tables as $table) { $t = array_values($table); $wpdb->query("OPTIMIZE TABLE " . $t[0]); wpo_debugLog('optimizing .... ' . $t[0]); } //$dateformat = __('l jS \of F Y h:i:s A'); $dateformat = 'l jS \\of F Y h:i:s A'; $thisdate = date($dateformat); list($part1, $part2) = wpo_getCurrentDBSize(); update_option(OPTION_NAME_LAST_OPT, $thisdate); wpo_updateTotalCleaned($part2); wpo_debugLog('Updating options with value +' . $part2); } // endif $this_options['optimize'] } }