C:\xampp\htdocs\landing\wp-content\plugins\wp-smushit\core\modules\async\class-async.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
<?php
/**
 * Class Async
 *
 * @package Smush\Core\Modules\Async
 * @since 2.5
 *
 * @author Umesh Kumar <umesh@incsub.com>
 *
 * @copyright (c) 2016, Incsub (http://incsub.com)
 */

namespace Smush\Core\Modules\Async;

use 
Exception;

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

/**
 * Class Async
 */
class Async extends Abstract_Async {

    
/**
     * Argument count.
     *
     * @var int $argument_count
     */
    
protected $argument_count 2;

    
/**
     * Priority.
     *
     * @var int $priority
     */
    
protected $priority 12;

    
/**
     * Whenever a attachment metadata is generated
     * Had to be hooked on generate and not update, else it goes in infinite loop
     *
     * @var string
     */
    
protected $action 'wp_generate_attachment_metadata';

    
/**
     * Prepare data for the asynchronous request
     *
     * @throws Exception If for any reason the request should not happen.
     *
     * @param array $data An array of data sent to the hook.
     *
     * @return array
     */
    
protected function prepare_data$data ) {
        
// We don't have the data, bail out.
        
if ( empty( $data ) ) {
            return 
$data;
        }

        
// Return a associative array.
        
$image_meta             = array();
        
$image_meta['metadata'] = ! empty( $data[0] ) ? $data[0] : '';
        
$image_meta['id']       = ! empty( $data[1] ) ? $data[1] : '';

        
/**
         * AJAX Thumbnail Rebuild integration.
         *
         * @see https://app.asana.com/0/14491813218786/730814863045197/f
         */
        
if ( ! empty( $_POST['action'] ) && 'ajax_thumbnail_rebuild' === $_POST['action'] && ! empty( $_POST['thumbnails'] ) ) { // Input var ok.
            
$image_meta['regen'] = wp_unslash$_POST['thumbnails'] ); // Input var ok.
        
}

        return 
$image_meta;
    }

    
/**
     * Run the async task action
     *
     * TODO: See if auto smush is enabled or not.
     * TODO: Check if async is enabled or not.
     */
    
protected function run_action() {
        
$metadata = ! empty( $_POST['metadata'] ) ? $_POST['metadata'] : '';
        
$id       = ! empty( $_POST['id'] ) ? $_POST['id'] : '';

        
// Get metadata from $_POST.
        
if ( ! empty( $metadata ) && wp_attachment_is_image$id ) ) {
            
// Allow the Asynchronous task to run.
            
do_action"wp_async_$this->action"$id );
        }
    }

}
x

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