Edit File by line
/home/zeestwma/ceyloniy.../wp-conte.../plugins/extendif.../app/Draft/Controll...
File: ImageController.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Image Controller
[3] Fix | Delete
*/
[4] Fix | Delete
[5] Fix | Delete
namespace Extendify\Draft\Controllers;
[6] Fix | Delete
[7] Fix | Delete
defined('ABSPATH') || die('No direct access.');
[8] Fix | Delete
[9] Fix | Delete
// Try to execute set the limit to something that will work for 60s duration.
[10] Fix | Delete
// phpcs:ignore WordPress.PHP.NoSilencedErrors, Generic.PHP.NoSilencedErrors.Discouraged
[11] Fix | Delete
if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
[12] Fix | Delete
// phpcs:ignore WordPress.PHP.NoSilencedErrors, Generic.PHP.NoSilencedErrors.Discouraged
[13] Fix | Delete
@set_time_limit(60);
[14] Fix | Delete
}
[15] Fix | Delete
[16] Fix | Delete
use Extendify\Shared\Services\Sanitizer;
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* The controller for uploading images to the Media Library.
[20] Fix | Delete
*/
[21] Fix | Delete
[22] Fix | Delete
class ImageController
[23] Fix | Delete
{
[24] Fix | Delete
/**
[25] Fix | Delete
* Upload the provided image
[26] Fix | Delete
*
[27] Fix | Delete
* @param \WP_REST_Request $request - The request.
[28] Fix | Delete
* @return \WP_REST_Response
[29] Fix | Delete
*/
[30] Fix | Delete
public static function uploadMedia(\WP_REST_Request $request)
[31] Fix | Delete
{
[32] Fix | Delete
if (! function_exists('\media_sideload_image')) {
[33] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/media.php';
[34] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/file.php';
[35] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/image.php';
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
$imageId = \media_sideload_image($request->get_param('source'), 0, null, 'id');
[39] Fix | Delete
[40] Fix | Delete
if ($request->get_param('alt_text')) {
[41] Fix | Delete
update_post_meta(
[42] Fix | Delete
$imageId,
[43] Fix | Delete
'_wp_attachment_image_alt',
[44] Fix | Delete
Sanitizer::sanitizeText($request->get_param('alt_text'))
[45] Fix | Delete
);
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
if ($request->get_param('caption')) {
[49] Fix | Delete
wp_update_post(
[50] Fix | Delete
Sanitizer::sanitizeArray([
[51] Fix | Delete
'ID' => $imageId,
[52] Fix | Delete
'post_excerpt' => $request->get_param('caption'),
[53] Fix | Delete
])
[54] Fix | Delete
);
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
$imageObject = \get_post($imageId);
[58] Fix | Delete
$altText = (get_post_meta($imageId, '_wp_attachment_image_alt', true))
[59] Fix | Delete
? get_post_meta($imageId, '_wp_attachment_image_alt', true)
[60] Fix | Delete
: '';
[61] Fix | Delete
[62] Fix | Delete
return new \WP_REST_Response(
[63] Fix | Delete
[
[64] Fix | Delete
'id' => $imageId,
[65] Fix | Delete
'caption' => ['raw' => $imageObject->post_excerpt],
[66] Fix | Delete
'source_url' => wp_get_attachment_url($imageId),
[67] Fix | Delete
'alt_text' => $altText,
[68] Fix | Delete
]
[69] Fix | Delete
);
[70] Fix | Delete
}
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function