PluginProbe
ManageWP Worker / 3.8.8
ManageWP Worker v3.8.8
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / plugins / cleanup / cleanup.php

cleanup.php in ManageWP Worker 3.8.8, at plugins/cleanup/cleanup.php

161 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*************************************************************
3 *
4 *
5 *
6 * ManageWP Worker Plugin
7 *
8 *
9 * Copyright (c) 2011 Prelovac Media
10 * www.prelovac.com
11 **************************************************************/
12
13 add_filter('mmb_stats_filter', mmb_get_extended_info);
14
15
16 function mmb_get_extended_info($stats)
17 {
18 $stats['num_revisions'] = mmb_num_revisions();
19 $stats['overhead'] = mmb_get_overhead();
20 $stats['num_spam_comments'] = mmb_num_spam_comments();
21 return $stats;
22 }
23
24 /* Revisions */
25
26 mmb_add_action('cleanup_delete', 'cleanup_delete_worker');
27
28 function cleanup_delete_worker($params = array()){
29 global $mmb_core;
30
31 $params_array = explode('_', $params['actions']);
32 $return_array = array();
33 foreach ($params_array as $param){
34 switch ($param){
35 case 'revision' :
36 if(mmb_delete_all_revisions()){
37 $return_array['revision'] = 'Revisions deleted.';
38 }else{
39 $return_array['revision'] = 'Revisions not deleted.';
40 }
41 break;
42 case 'overhead' :
43 if(mmb_clear_overhead()){
44 $return_array['overhead'] = 'Overhead cleared.';
45 }else{
46 $return_array['overhead'] = 'Overhead not cleared.';
47 }
48 break;
49 case 'comment' :
50 if(mmb_delete_spam_comments()){
51 $return_array['comment'] = 'Comments deleted';
52 }else{
53 $return_array['comment'] = 'Comments not deleted';
54 }
55 break;
56 default:
57 break;
58 }
59
60 }
61
62 unset($params);
63
64 mmb_response($return_array, true);
65 }
66
67 function mmb_num_revisions() {
68 global $wpdb;
69 $sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'revision'";
70 $num_revisions = $wpdb->get_var($wpdb->prepare($sql));
71 return $num_revisions;
72 }
73
74 function mmb_select_all_revisions() {
75 global $wpdb;
76 $sql = "SELECT * FROM $wpdb->posts WHERE post_type = 'revision'";
77 $revisions = $wpdb->get_results($wpdb->prepare($sql));
78 return $revisions;
79 }
80
81 function mmb_delete_all_revisions() {
82 global $wpdb;
83 $sql = "DELETE a,b,c FROM $wpdb->posts a LEFT JOIN $wpdb->term_relationships b ON (a.ID = b.object_id) LEFT JOIN $wpdb->postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision'";
84 $revisions = $wpdb->query($wpdb->prepare($sql));
85 return $revisions;
86 }
87
88
89
90 /* Optimize */
91
92 function mmb_get_overhead()
93 {
94 global $wpdb, $mmb_core;
95 $tot_data = 0;
96 $tot_idx = 0;
97 $tot_all = 0;
98 $query = 'SHOW TABLE STATUS FROM '. DB_NAME;
99 $tables = $wpdb->get_results($query,ARRAY_A);
100 foreach($tables as $table)
101 {
102 $tot_data = $table['Data_length'];
103 $tot_idx = $table['Index_length'];
104 $total = $tot_data + $tot_idx;
105 $total = $total / 1024 ;
106 $total = round ($total,3);
107 $gain= $table['Data_free'];
108 $gain = $gain / 1024 ;
109 $total_gain += $gain;
110 $gain = round ($gain,3);
111
112 }
113
114 return round($total_gain,3);
115 }
116
117 function mmb_clear_overhead()
118 {
119 global $wpdb;
120 $tables = $wpdb->get_col("SHOW TABLES");
121 foreach ($tables as $table_name) {
122 $table_string .= $table_name . ",";
123 }
124 $table_string = substr($table_string,0,strlen($table_string)-1); //remove last ,
125
126 $table_string = rtrim($table_string);
127
128 $query = "OPTIMIZE TABLE $table_string";
129
130 $optimize = $wpdb->query($query);
131 return $optimize ? true : false;
132 }
133
134
135
136 /* Spam Comments */
137
138 function mmb_num_spam_comments()
139 {
140 global $wpdb;
141 $sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'spam'";
142 $num_spams = $wpdb->get_var($wpdb->prepare($sql));
143 return $num_spams;
144 }
145
146 function mmb_delete_spam_comments()
147 {
148 global $wpdb;
149 $sql = "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'";
150 $spams = $wpdb->query($wpdb->prepare($sql));
151 return $sql;
152 }
153
154
155 function mmb_get_spam_comments() {
156 global $wpdb;
157 $sql = "SELECT * FROM $wpdb->comments as a LEFT JOIN $wpdb->commentmeta as b WHERE a.comment_ID = b.comment_id AND a.comment_approved = 'spam'";
158 $spams = $wpdb->get_results($wpdb->prepare($sql));
159 return $spams;
160 }
161 ?>