Edit File by line
/home/zeestwma/ceyloniy.../wp-conte.../plugins/extendif.../app/Shared/Controll...
File: PatternPlaceholderController.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Controller for updating patterns based on their dependencies.
[3] Fix | Delete
*/
[4] Fix | Delete
[5] Fix | Delete
namespace Extendify\Shared\Controllers;
[6] Fix | Delete
[7] Fix | Delete
defined('ABSPATH') || die('No direct access.');
[8] Fix | Delete
[9] Fix | Delete
use Extendify\Shared\Services\PluginDependencies\Forms\WPForms;
[10] Fix | Delete
use Extendify\Shared\Services\PluginDependencies\Forms\ContactForm7;
[11] Fix | Delete
use Extendify\Shared\Services\PluginDependencies\WooCommerce;
[12] Fix | Delete
use Extendify\Shared\Services\PluginDependencies\SimplyBook;
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* The controller for interacting with the pattern deps.
[16] Fix | Delete
*/
[17] Fix | Delete
[18] Fix | Delete
class PatternPlaceholderController
[19] Fix | Delete
{
[20] Fix | Delete
// phpcs:ignore PSR12.Properties.ConstantVisibility.NotFound
[21] Fix | Delete
const PLUGIN_HANDLERS = [
[22] Fix | Delete
'contact-form-7' => ContactForm7::class,
[23] Fix | Delete
'wpforms-lite' => WPForms::class,
[24] Fix | Delete
'woocommerce' => WooCommerce::class,
[25] Fix | Delete
'simplybook' => SimplyBook::class,
[26] Fix | Delete
];
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* Replace all placeholders in the given content
[30] Fix | Delete
*
[31] Fix | Delete
* @param \WP_REST_Request $request - The request.
[32] Fix | Delete
* @return \WP_REST_Response
[33] Fix | Delete
*/
[34] Fix | Delete
public static function processPlaceholders($request)
[35] Fix | Delete
{
[36] Fix | Delete
$patterns = $request->get_param('patterns');
[37] Fix | Delete
[38] Fix | Delete
$patterns = array_map(function ($pattern) {
[39] Fix | Delete
$newCode = ($pattern['patternReplacementCode'] ?? null);
[40] Fix | Delete
$pluginDependency = ($pattern['pluginDependency'] ?? null);
[41] Fix | Delete
if (!$newCode || !$pluginDependency) {
[42] Fix | Delete
return $pattern;
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
$metadata = null;
[46] Fix | Delete
if (isset($pattern['patternMetadata'])) {
[47] Fix | Delete
$metadata = json_decode($pattern['patternMetadata'], true);
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
$handlerClass = isset(self::PLUGIN_HANDLERS[$pluginDependency])
[51] Fix | Delete
? self::PLUGIN_HANDLERS[$pluginDependency]
[52] Fix | Delete
: null;
[53] Fix | Delete
if ($handlerClass && isset($metadata['key'])) {
[54] Fix | Delete
$pattern['code'] = $handlerClass::create($pattern['code'], $metadata['key'], $newCode);
[55] Fix | Delete
return $pattern;
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
// We added a feature this version doesn't yet support.
[59] Fix | Delete
return $pattern;
[60] Fix | Delete
}, $patterns);
[61] Fix | Delete
[62] Fix | Delete
// if any of the pattern code is a wp_error, we need to fail.
[63] Fix | Delete
foreach ($patterns as $pattern) {
[64] Fix | Delete
if (is_wp_error($pattern['code'])) {
[65] Fix | Delete
return new \WP_REST_Response($pattern['code'], 422);
[66] Fix | Delete
}
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
return new \WP_REST_Response($patterns);
[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