C:\xampp\htdocs\landing\wp-content\plugins\wp-optimize\optimizations\postmeta.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
<?php

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

class 
WP_Optimization_postmeta extends WP_Optimization {

    public 
$ui_sort_order 8000;

    public 
$available_for_auto false;

    public 
$available_for_saving true;

    public 
$auto_default false;

    
/**
     * Prepare data for preview widget.
     *
     * @param array $params
     *
     * @return array
     */
    
public function preview($params) {
        
// get data requested for preview.
        
$sql $this->wpdb->prepare(
            
"SELECT pm.* FROM `" $this->wpdb->postmeta "` pm".
            
" LEFT JOIN `" $this->wpdb->posts "` wp ON wp.ID = pm.post_id".
            
" WHERE wp.ID IS NULL".
            
" ORDER BY pm.meta_id LIMIT %d, %d;",
            array(
                
$params['offset'],
                
$params['limit'],
            )
        );

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

        
// get total count post meta for optimization.
        
$sql "SELECT COUNT(*) FROM `" $this->wpdb->postmeta "` pm LEFT JOIN `" $this->wpdb->posts "` wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;";

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

        return array(
            
'id_key' => 'meta_id',
            
'columns' => array(
                
'meta_id' => __('ID''wp-optimize'),
                
'post_id' => __('Post ID''wp-optimize'),
                
'meta_key' => __('Meta Key''wp-optimize'),
                
'meta_value' => __('Meta Value''wp-optimize'),
            ),
            
'offset' => $params['offset'],
            
'limit' => $params['limit'],
            
'total' => $total,
            
'data' => $this->htmlentities_array($posts, array('ID')),
            
'message' => $total '' __('No orphaned post meta data in your database''wp-optimize'),
        );
    }

    
/**
     * Do actions after optimize() function.
     */
    
public function after_optimize() {
        
$message sprintf(_n('%s orphaned post meta data deleted''%s orphaned post meta data deleted'$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() {
        
$clean "DELETE pm FROM `" $this->wpdb->postmeta "` pm LEFT JOIN `" $this->wpdb->posts "` wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL";

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

        
$clean .= ";";

        
$postmeta $this->query($clean);
        
$this->processed_count += $postmeta;
    }

    
/**
     * Do actions after get_info() function.
     */
    
public function after_get_info() {
        if (
$this->found_count) {
            
$message sprintf(_n('%s orphaned post meta data in your database''%s orphaned post meta data in your database'$this->found_count'wp-optimize'), number_format_i18n($this->found_count));
        } else {
            
$message __('No orphaned post meta data in your database''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 to message.
        
if ($this->found_count 0) {
            
$message $this->get_preview_link($message);
        }

        
$this->register_output($message);
    }

    
/**
     * Get count of unoptimized items.
     */
    
public function get_info() {
        
$sql "SELECT COUNT(*) FROM `" $this->wpdb->postmeta "` pm LEFT JOIN `" $this->wpdb->posts "` wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;";
        
$postmeta $this->wpdb->get_var($sql);

        
$this->found_count += $postmeta;
    }

    public function 
settings_label() {
        return 
__('Clean post meta data''wp-optimize');
    }

    
/**
     * N.B. This is not currently used; it was commented out in 1.9.1
     *
     * @return string Returns the description once auto remove option has ran
     */
    
public function get_auto_option_description() {
        return 
__('Remove orphaned post meta''wp-optimize');
    }
}
x

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