C:\xampp\htdocs\landing\wp-content\plugins\wp-smushit\core\class-rest.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
<?php
/**
 * Smush integration with Rest API: Rest class
 *
 * @package Smush\Core
 * @since 2.8.0
 *
 * @author Anton Vanyukov <anton@incsub.com>
 *
 * @copyright (c) 2018, Incsub (http://incsub.com)
 */

namespace Smush\Core;

use 
WP_Smush;

if ( ! 
defined'WPINC' ) ) {
    die;
}

/**
 * Singleton class Rest for extending the WordPress REST API interface.
 *
 * @since 2.8.0
 */
class Rest {

    
/**
     * Rest constructor.
     */
    
public function __construct() {
        
// Register smush meta fields and callbacks for the image object in the
        // wp-json/wp/v2/media REST API endpoint.
        
add_action'rest_api_init', array( $this'register_smush_meta' ) );
    }

    
/**
     * Callback for rest_api_init action.
     *
     * @since 2.8.0
     */
    
public function register_smush_meta() {
        
register_rest_field(
            
'attachment',
            
'smush',
            array(
                
'get_callback' => array( $this'register_image_stats' ),
                
'schema'       => array(
                    
'description' => __'Smush data.''wp-smushit' ),
                    
'type'        => 'string',
                ),
            )
        );
    }

    
/**
     * Add image stats to the wp-json/wp/v2/media REST API endpoint.
     *
     * Will add the stats from wp-smpro-smush-data image meta key to the media REST API endpoint.
     * If image is Smushed, the stats from the meta can be queried, if the not - the status of Smushing
     * will be displayed as a string in the API.
     *
     * @since 2.8.0
     *
     * @link https://developer.wordpress.org/rest-api/reference/media/
     *
     * @param array $image  Image array.
     *
     * @return array|string
     */
    
public function register_image_stats$image ) {
        if ( 
get_option'smush-in-progress-' $image['id'], false ) ) {
            
$status_txt __'Smushing in progress''wp-smushit' );
            return 
$status_txt;
        }

        
$wp_smush_data get_post_meta$image['id'], Modules\Smush::$smushed_meta_keytrue );

        if ( empty( 
$wp_smush_data ) ) {
            
$status_txt __'Not processed''wp-smushit' );
            return 
$status_txt;
        }

        
$wp_resize_savings  get_post_meta$image['id'], WP_SMUSH_PREFIX 'resize_savings'true );
        
$conversion_savings get_post_meta$image['id'], WP_SMUSH_PREFIX 'pngjpg_savings'true );

        
$combined_stats WP_Smush::get_instance()->core()->combined_stats$wp_smush_data$wp_resize_savings );
        
$combined_stats WP_Smush::get_instance()->core()->combine_conversion_stats$combined_stats$conversion_savings );

        return 
$combined_stats;
    }

}
x

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