C:\xampp\htdocs\landing\wp-content\plugins\wp-optimize\optimizations\trash.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php

if (!defined('WPO_VERSION')) die('No direct access allowed');

/**
 * Class WP_Optimization_trash
 */
class WP_Optimization_trash extends WP_Optimization {

    public 
$available_for_auto true;

    public 
$auto_default true;

    public 
$setting_default true;

    public 
$available_for_saving true;
    
    public 
$ui_sort_order 3010;

    protected 
$setting_id 'trash';

    protected 
$auto_id 'trash';

    
/**
     * Prepare data for preview widget.
     *
     * @param array $params
     *
     * @return array
     */
    
public function preview($params) {

        
$retention_subquery '';

        if (
'true' == $this->retention_enabled) {
            
$retention_subquery ' and post_modified < NOW() - INTERVAL ' $this->retention_period ' WEEK';
        }

        
// get data requested for preview.
        
$sql $this->wpdb->prepare(
            
"SELECT `ID`, `post_title`, `post_date`".
            
" FROM `" $this->wpdb->posts "`".
            
" WHERE post_status = 'trash'".
            
$retention_subquery.
            
" ORDER BY `ID` LIMIT %d, %d;",
            array(
                
$params['offset'],
                
$params['limit'],
            )
        );

        
$posts $this->wpdb->get_results($sqlARRAY_A);

        
// fix empty revision titles.
        
if (!empty($posts)) {
            foreach (
$posts as $key => $post) {
                
$posts[$key]['post_title'] = array(
                    
'text' => '' == $post['post_title'] ? '('.__('no title''wp-optimize').')' $post['post_title'],
                    
'url' => get_edit_post_link($post['ID']),
                );
            }
        }

        
// get total count auto-draft for optimization.
        
$sql "SELECT COUNT(*) FROM `" $this->wpdb->posts "` WHERE post_status = 'trash'";

        if (
'true' == $this->retention_enabled) {
            
$sql .= ' and post_modified < NOW() - INTERVAL ' $this->retention_period ' WEEK';
        }
        
$sql .= ';';

        
$total $this->wpdb->get_var($sql);

        return array(
            
'id_key' => 'ID',
            
'columns' => array(
                
'ID' => __('ID''wp-optimize'),
                
'post_title' => __('Title''wp-optimize'),
                
'post_date' => __('Date''wp-optimize'),
            ),
            
'offset' => $params['offset'],
            
'limit' => $params['limit'],
            
'total' => $total,
            
'data' => $this->htmlentities_array($posts, array('ID')),
            
'message' => $total '' __('No trashed posts found''wp-optimize'),
        );
    }

    
/**
     * Do actions after optimize() function.
     */
    
public function after_optimize() {
        
$message sprintf(_n('%s post removed from Trash''%s posts removed from Trash'$this->processed_count'wp-optimize'), number_format_i18n($this->processed_count));

        if (
$this->is_multisite_mode()) {
            
$message .= ' ' sprintf(_n('across %s site''across %s sites'count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
        }

        
$this->logger->info($message);
        
$this->register_output($message);
    }

    
/**
     * Do optimization.
     */
    
public function optimize() {

        
$remove_ids_sql "SELECT ID FROM `" $this->wpdb->posts "` WHERE post_status = 'trash'";

        if (
'true' == $this->retention_enabled) {
            
$remove_ids_sql .= ' AND post_modified < NOW() - INTERVAL ' $this->retention_period ' WEEK';
        }

        
// get trashed post ids.
        
$post_remove_ids $this->wpdb->get_col($remove_ids_sql);

        
// if optimize called from preview dialog then get posted ids.
        
if (isset($this->data['ids'])) {
            
$post_remove_ids array_intersect($post_remove_ids$this->data['ids']);
        }

        
// remove related data for trashed posts.
        
if (!empty($post_remove_ids)) {
            
$post_remove_ids join(','$post_remove_ids);

            
// remove related postmeta.
            
$clean "DELETE FROM `" $this->wpdb->postmeta "` WHERE post_id IN (" $post_remove_ids ");";
            
$this->wpdb->query($clean);

            
// remove related term relationships.
            
$clean "DELETE FROM `" $this->wpdb->term_relationships "` WHERE object_id IN (" $post_remove_ids ");";
            
$this->wpdb->query($clean);

            
// remove related comments and commentmeta.
            
$clean "DELETE c, cm FROM `" $this->wpdb->comments "` c LEFT JOIN `" $this->wpdb->commentmeta "` cm ON c.comment_ID = cm.comment_id WHERE c.comment_post_ID IN (" $post_remove_ids ");";
            
$this->wpdb->query($clean);
        }

        
$clean "DELETE FROM `" $this->wpdb->posts "` WHERE post_status = 'trash'";

        if (
'true' == $this->retention_enabled) {
            
$clean .= ' AND post_modified < NOW() - INTERVAL ' $this->retention_period ' WEEK';
        }

        
// if posted ids in params, then remove only selected items. used by preview widget.
        
if (isset($this->data['ids'])) {
            
$clean .= ' AND `ID` in ('.join(','$this->data['ids']).')';
        }

        
$clean .= ';';

        
// remove trashed posts.
        
$posttrash $this->query($clean);
        
$this->processed_count += $posttrash;

    }

    
/**
     * Do actions after get_info() function.
     */
    
public function after_get_info() {
        if (
$this->found_count 0) {
            
$message sprintf(_n('%s trashed post in your database''%s trashed posts in your database'$this->found_count'wp-optimize'), number_format_i18n($this->found_count));
        } else {
            
$message __('No trashed posts found''wp-optimize');
        }

        if (
$this->is_multisite_mode()) {
            
$message .= ' ' sprintf(_n('across %s site''across %s sites'count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));
        }

        
// add preview link for output.
        
if (!= $this->found_count && null != $this->found_count) {
            
$message $this->get_preview_link($message);
        }

        
$this->register_output($message);
    }

    
/**
     * Return info about not optimized records
     */
    
public function get_info() {

        
$sql "SELECT COUNT(*) FROM `" $this->wpdb->posts "` WHERE post_status = 'trash'";
        if (
'true' == $this->retention_enabled) {
            
$sql .= ' and post_modified < NOW() - INTERVAL ' $this->retention_period ' WEEK';
        }
        
$sql .= ';';

        
$trash $this->wpdb->get_var($sql);
        
$this->found_count += $trash;

    }

    
/**
     * Return settings label
     *
     * @return string|void
     */
    
public function settings_label() {

        if (
'true' == $this->retention_enabled) {
            return 
sprintf(__('Clean trashed posts which are older than %d weeks''wp-optimize'), $this->retention_period);
        } else {
            return 
__('Clean all trashed posts''wp-optimize');
        }
    }

    
/**
     * Return description
     *
     * @return string|void
     */
    
public function get_auto_option_description() {
        return 
__('Remove trashed posts''wp-optimize');
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586