Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wp-smush.../core
File: class-rest.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Smush integration with Rest API: Rest class
[2] Fix | Delete
*
[3] Fix | Delete
* @package Smush\Core
[4] Fix | Delete
* @since 2.8.0
[5] Fix | Delete
*
[6] Fix | Delete
* @author Anton Vanyukov <anton@incsub.com>
[7] Fix | Delete
*
[8] Fix | Delete
* @copyright (c) 2018, Incsub (http://incsub.com)
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
namespace Smush\Core;
[12] Fix | Delete
[13] Fix | Delete
use WP_Smush;
[14] Fix | Delete
[15] Fix | Delete
if ( ! defined( 'WPINC' ) ) {
[16] Fix | Delete
die;
[17] Fix | Delete
}
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* Singleton class Rest for extending the WordPress REST API interface.
[21] Fix | Delete
*
[22] Fix | Delete
* @since 2.8.0
[23] Fix | Delete
*/
[24] Fix | Delete
class Rest {
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* Rest constructor.
[28] Fix | Delete
*/
[29] Fix | Delete
public function __construct() {
[30] Fix | Delete
// Register smush meta fields and callbacks for the image object in the
[31] Fix | Delete
// wp-json/wp/v2/media REST API endpoint.
[32] Fix | Delete
add_action( 'rest_api_init', array( $this, 'register_smush_meta' ) );
[33] Fix | Delete
[34] Fix | Delete
// Custom route for handling configs.
[35] Fix | Delete
add_action( 'rest_api_init', array( $this, 'register_configs_route' ) );
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* Callback for rest_api_init action.
[40] Fix | Delete
*
[41] Fix | Delete
* @since 2.8.0
[42] Fix | Delete
*/
[43] Fix | Delete
public function register_smush_meta() {
[44] Fix | Delete
register_rest_field(
[45] Fix | Delete
'attachment',
[46] Fix | Delete
'smush',
[47] Fix | Delete
array(
[48] Fix | Delete
'get_callback' => array( $this, 'register_image_stats' ),
[49] Fix | Delete
'schema' => array(
[50] Fix | Delete
'description' => __( 'Smush data.', 'wp-smushit' ),
[51] Fix | Delete
'type' => 'string',
[52] Fix | Delete
),
[53] Fix | Delete
)
[54] Fix | Delete
);
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* Add image stats to the wp-json/wp/v2/media REST API endpoint.
[59] Fix | Delete
*
[60] Fix | Delete
* Will add the stats from wp-smpro-smush-data image meta key to the media REST API endpoint.
[61] Fix | Delete
* If image is Smushed, the stats from the meta can be queried, if the not - the status of Smushing
[62] Fix | Delete
* will be displayed as a string in the API.
[63] Fix | Delete
*
[64] Fix | Delete
* @since 2.8.0
[65] Fix | Delete
*
[66] Fix | Delete
* @link https://developer.wordpress.org/rest-api/reference/media/
[67] Fix | Delete
*
[68] Fix | Delete
* @param array $image Image array.
[69] Fix | Delete
*
[70] Fix | Delete
* @return array|string
[71] Fix | Delete
*/
[72] Fix | Delete
public function register_image_stats( $image ) {
[73] Fix | Delete
if ( get_transient( 'smush-in-progress-' . $image['id'] ) ) {
[74] Fix | Delete
return __( 'Smushing in progress', 'wp-smushit' );
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
$wp_smush_data = get_post_meta( $image['id'], Modules\Smush::$smushed_meta_key, true );
[78] Fix | Delete
[79] Fix | Delete
if ( empty( $wp_smush_data ) ) {
[80] Fix | Delete
return __( 'Not processed', 'wp-smushit' );
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
$wp_resize_savings = get_post_meta( $image['id'], 'wp-smush-resize_savings', true );
[84] Fix | Delete
$conversion_savings = get_post_meta( $image['id'], 'wp-smush-pngjpg_savings', true );
[85] Fix | Delete
[86] Fix | Delete
$combined_stats = WP_Smush::get_instance()->core()->combined_stats( $wp_smush_data, $wp_resize_savings );
[87] Fix | Delete
[88] Fix | Delete
return WP_Smush::get_instance()->core()->combine_conversion_stats( $combined_stats, $conversion_savings );
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Registers the custom route for handling configs.
[93] Fix | Delete
*
[94] Fix | Delete
* @since 3.8.6
[95] Fix | Delete
*/
[96] Fix | Delete
public function register_configs_route() {
[97] Fix | Delete
$configs_handler = new Configs();
[98] Fix | Delete
register_rest_route(
[99] Fix | Delete
'wp-smush/v1',
[100] Fix | Delete
'/preset_configs/',
[101] Fix | Delete
array(
[102] Fix | Delete
array(
[103] Fix | Delete
'methods' => 'GET',
[104] Fix | Delete
'callback' => array( $configs_handler, 'get_callback' ),
[105] Fix | Delete
'permission_callback' => array( $configs_handler, 'permission_callback' ),
[106] Fix | Delete
),
[107] Fix | Delete
array(
[108] Fix | Delete
'methods' => 'POST',
[109] Fix | Delete
'callback' => array( $configs_handler, 'post_callback' ),
[110] Fix | Delete
'permission_callback' => array( $configs_handler, 'permission_callback' ),
[111] Fix | Delete
),
[112] Fix | Delete
)
[113] Fix | Delete
);
[114] Fix | Delete
}
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function