403Webshell
Server IP : 208.122.213.31  /  Your IP : 216.73.216.45
Web Server : Apache
System : Linux msd6191.mjhst.com 4.18.0-553.137.1.el8_10.x86_64 #1 SMP Wed Jun 24 11:40:24 UTC 2026 x86_64
User : WHMCS_MIA_382 ( 1001)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/httpd/html/baberankings.com/wp-content/plugins/webp-uploads/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/httpd/html/baberankings.com/wp-content/plugins/webp-uploads/rest-api.php
<?php
/**
 * REST API integration for the plugin.
 *
 * @package webp-uploads
 *
 * @since 1.0.0
 */

declare( strict_types = 1 );

// @codeCoverageIgnoreStart
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}
// @codeCoverageIgnoreEnd

/**
 * Updates the response for an attachment to include sources for additional mime types available the image.
 *
 * @since 1.0.0
 *
 * @param WP_REST_Response $response The original response object.
 * @param WP_Post          $post     The post object.
 * @return WP_REST_Response A new response object for the attachment with additional sources.
 */
function webp_uploads_update_rest_attachment( WP_REST_Response $response, WP_Post $post ): WP_REST_Response {
	$data = $response->get_data();
	if (
		! is_array( $data ) ||
		! isset( $data['media_details'] ) ||
		! is_array( $data['media_details'] ) ||
		! isset( $data['media_details']['sizes'] ) ||
		! is_array( $data['media_details']['sizes'] ) ) {
		return $response;
	}

	foreach ( $data['media_details']['sizes'] as $size => &$details ) {

		if (
			! is_array( $details ) ||
			! isset( $details['sources'], $details['source_url'] ) ||
			! is_array( $details['sources'] ) ||
			! is_string( $details['source_url'] )
		) {
			continue;
		}

		$image_url_basename = wp_basename( $details['source_url'] );
		foreach ( $details['sources'] as $mime => &$mime_details ) {
			if ( is_array( $mime_details ) && isset( $mime_details['file'] ) && is_string( $mime_details['file'] ) ) {
				$mime_details['source_url'] = str_replace( $image_url_basename, $mime_details['file'], $details['source_url'] );
			}
		}
		unset( $mime_details );
	}
	unset( $details );

	$full_src = wp_get_attachment_image_src( $post->ID, 'full' );
	if (
		isset( $full_src[0] ) &&
		isset( $data['media_details']['sources'] ) &&
		is_array( $data['media_details']['sources'] ) &&
		isset( $data['media_details']['sizes']['full'] ) &&
		is_array( $data['media_details']['sizes']['full'] )
	) {
		$full_url_basename = wp_basename( $full_src[0] );
		foreach ( $data['media_details']['sources'] as $mime => &$mime_details ) {
			if ( is_array( $mime_details ) && isset( $mime_details['file'] ) && is_string( $mime_details['file'] ) ) {
				$mime_details['source_url'] = str_replace( $full_url_basename, $mime_details['file'], $full_src[0] );
			}
		}
		unset( $mime_details );

		$data['media_details']['sizes']['full']['sources'] = $data['media_details']['sources'];
		unset( $data['media_details']['sources'] );
	}

	return new WP_REST_Response( $data );
}
add_filter( 'rest_prepare_attachment', 'webp_uploads_update_rest_attachment', 10, 2 );

Youez - 2016 - github.com/yon3zu
LinuXploit