function optimizeTablesQuick($Optimize = false)
{
    global $wpdb;
    $total_gain = 0;
    $row_usage = 0;
    $data_usage = 0;
    $index_usage = 0;
    $overhead_usage = 0;
    $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
    foreach ($tablesstatus as $tablestatus) {
        $row_usage += $tablestatus->Rows;
        $data_usage += $tablestatus->Data_length;
        $index_usage += $tablestatus->Index_length;
        $overhead_usage += $tablestatus->Data_free;
        $total_gain += $tablestatus->Data_free;
    }
    if ($Optimize == true) {
        if (WPO_TABLE_TYPE != 'innodb') {
            $tables = $wpdb->get_col("SHOW TABLES");
            foreach ($tables as $table_name) {
                $local_query = 'OPTIMIZE TABLE ' . $table_name;
                $result_query = $wpdb->query($local_query);
                wpo_updateTotalCleaned(strval($total_gain));
                $total_gain = 0;
            }
            // if innodb is false
        }
    }
}
function optimizeTablesQuick($Optimize)
{
    global $wpdb;
    $total_gain = 0;
    $row_usage = 0;
    $data_usage = 0;
    $index_usage = 0;
    $overhead_usage = 0;
    $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
    foreach ($tablesstatus as $tablestatus) {
        $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;
        }
    }
    if ($Optimize == "yes") {
        //if ($tablestatus->Engine != 'InnoDB'){
        $tables = $wpdb->get_col("SHOW TABLES");
        foreach ($tables as $table_name) {
            $local_query = 'OPTIMIZE TABLE `' . $table_name . '`';
            wpo_debugLog('optimizing .... ' . $table_name);
            $result_query = $wpdb->query($local_query);
        }
        //end for
        wpo_updateTotalCleaned(strval($total_gain));
        // #TODO for testing only
        // $thistime = current_time( "timestamp", 0 );
        // $thedate = gmdate(get_option('date_format') . ' ' . get_option('time_format'), $thistime );
        // list($part3, $part4) = wpo_getCurrentDBSize();
        // wpo_sendEmail($thedate, strval($part4)); //TODO TEMPORARY - send email to admin
        // wpo_debugLog('Invoked+ Updating options with value +'.$part4);
        wpo_debugLog('Total Gain .... ' . strval($total_gain));
    }
    //end if
    //
    // clear up total gain values
    $total_gain = 0;
}
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 optimizeTables($Optimize = false)
{
    ?>
<a name="report">&nbsp;</a>
<h3><?php 
    _e('Database Tables Report', 'wp-optimize');
    ?>
</h3>
<h3><?php 
    _e('Database Name:', 'wp-optimize');
    ?>
 '<?php 
    _e(DB_NAME, 'wp-optimize');
    ?>
'</h3>
<?php 
    if ($Optimize) {
        ?>

<p><?php 
        _e('Optimized all the tables found in the database.', 'wp-optimize');
        ?>
</p>
<?php 
    }
    ?>


<table class="widefat fixed" cellspacing="0">
<thead>
	<tr>
	<th scope="col"><?php 
    _e('Table', 'wp-optimize');
    ?>
</th>
	<th scope="col"><?php 
    _e('Size', 'wp-optimize');
    ?>
</th>
	<th scope="col"><?php 
    _e('Status', 'wp-optimize');
    ?>
</th>
	<th scope="col"><?php 
    _e('Space Save', 'wp-optimize');
    ?>
</th>
	</tr>
</thead>
<tfoot>
	<tr>
	<th scope="col"><?php 
    _e('Table', 'wp-optimize');
    ?>
</th>
	<th scope="col"><?php 
    _e('Size', 'wp-optimize');
    ?>
</th>
	<th scope="col"><?php 
    _e('Status', 'wp-optimize');
    ?>
</th>
	<th scope="col"><?php 
    _e('Space Save', 'wp-optimize');
    ?>
</th>
	</tr>
</tfoot>
<tbody id="the-list">
<?php 
    $alternate = ' class="alternate"';
    $db_clean = DB_NAME;
    $tot_data = 0;
    $total_gain = 0;
    $total_db_space = 0;
    $total_db_space_a = 0;
    $tot_idx = 0;
    $tot_all = 0;
    //$local_query = 'SHOW TABLE STATUS FROM '. DB_NAME;
    $local_query = 'SHOW TABLE STATUS FROM `' . DB_NAME . '`';
    $result = mysql_query($local_query);
    //if (mysql_num_rows($result)){
    //fix by mikel king
    if (mysql_num_rows($result) && is_resource($result)) {
        while ($row = mysql_fetch_array($result)) {
            $tot_data = $row['Data_length'];
            $tot_idx = $row['Index_length'];
            $total = $tot_data + $tot_idx;
            $total = $total / 1024;
            $total = round($total, 3);
            $total_db_space = $tot_data + $tot_idx;
            $total_db_space = $total_db_space / 1024;
            $total_db_space_a += $total_db_space;
            $total_db_space = round($total_db_space, 3);
            $gain = $row['Data_free'];
            $gain = $gain / 1024;
            $total_gain += $gain;
            $gain = round($gain, 3);
            if (isset($_POST["optimize-db"])) {
                $local_query = 'OPTIMIZE TABLE ' . $row[0];
                $resultat = mysql_query($local_query);
                //echo "optimization";
            }
            if ($gain == 0) {
                echo "<tr" . $alternate . ">\n\t\t\t\t\t<td class='column-name'>" . $row[0] . "</td>\n\t\t\t\t\t<td class='column-name'>" . $total . " Kb" . "</td>\n\t\t\t\t\t<td class='column-name'>" . __('Already Optimized', 'wp-optimize') . "</td>\n\t\t\t\t\t<td class='column-name'>0 Kb</td>\n\t\t\t\t\t</tr>\n";
            } else {
                if (isset($_POST["optimize-db"])) {
                    echo "<tr" . $alternate . ">\n\t\t\t\t\t<td class='column-name'>" . $row[0] . "</td>\n\t\t\t\t\t<td class='column-name'>" . $total . " Kb" . "</td>\n          <td class='column-name' style=\"color: #0000FF;\">" . __('Optimized', 'wp-optimize') . "</td>\n\t\t\t\t\t<td class='column-name'>" . $gain . " Kb</td>\n\t\t\t\t\t</tr>\n";
                } else {
                    echo "<tr" . $alternate . ">\n\t\t\t\t\t<td class='column-name'>" . $row[0] . "</td>\n\t\t\t\t\t<td class='column-name'>" . $total . " Kb" . "</td>\n          <td class='column-name' style=\"color: #FF0000;\">" . __('Need to Optimize', 'wp-optimize') . "</td>\n\t\t\t\t\t<td class='column-name'>" . $gain . " Kb</td>\n\t\t\t\t\t</tr>\n";
                }
            }
            $alternate = empty($alternate) ? ' class="alternate"' : '';
        }
    }
    ?>
</tbody>
</table>
<a name="total">&nbsp;</a>
<h3><?php 
    _e('Total Size of Database', 'wp-optimize');
    ?>
:</h3>
<h2><?php 
    echo round($total_db_space_a, 3);
    ?>
 Kb</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 
        _e('Total Space Saved', 'wp-optimize');
        ?>
: <?php 
        echo $total_gain;
        wpo_updateTotalCleaned(strval($total_gain));
        ?>
 Kb</p>
  <?php 
    } else {
        $total_gain = round($total_gain, 3);
        ?>
  <?php 
        if (!$total_gain == 0) {
            ?>

<h3><?php 
            _e('Optimization Possibility', 'wp-optimize');
            ?>
:</h3>
<p style="color: #FF0000;"><?php 
            _e('Total space can be saved', 'wp-optimize');
            ?>
: <?php 
            echo $total_gain;
            ?>
 Kb</p>
  <?php 
        }
    }
    ?>

<?php 
}
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 
}
Exemple #6
0
function optimizeTablesQuick($Optimize)
{
    global $wpdb;
    $total_gain = 0;
    $row_usage = 0;
    $data_usage = 0;
    $index_usage = 0;
    $overhead_usage = 0;
    $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
    foreach ($tablesstatus as $tablestatus) {
        $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;
        }
    }
    if ($Optimize == "yes") {
        //if ($tablestatus->Engine != 'InnoDB'){
        $tables = $wpdb->get_col("SHOW TABLES");
        foreach ($tables as $table_name) {
            $local_query = 'OPTIMIZE TABLE `' . $table_name . '`';
            wpo_debugLog('optimizing .... ' . $table_name);
            $result_query = $wpdb->query($local_query);
        }
        //end for
        wpo_updateTotalCleaned(strval($total_gain));
        wpo_debugLog('Total Gain .... ' . strval($total_gain));
    }
    //end if
    //
    // clear up total gain values
    $total_gain = 0;
}
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 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']
    }
}