bd45e84634
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
159 lines
4.5 KiB
PHP
159 lines
4.5 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
// Autoloader (без изменений)
|
|
spl_autoload_register(static function (string $class): void {
|
|
if (strpos($class, 'Cf7stg\\') !== 0) {
|
|
return;
|
|
}
|
|
$relative = substr($class, strlen('Cf7stg\\'));
|
|
$slug = strtolower(preg_replace('/([a-z0-9])([A-Z])/', '$1-$2', $relative));
|
|
$slug = str_replace('_', '-', $slug);
|
|
$path = __DIR__ . '/../includes/class-' . $slug . '.php';
|
|
if (is_file($path)) {
|
|
require_once $path;
|
|
}
|
|
});
|
|
|
|
// Stateful WP shims
|
|
final class Cf7stgWpShimState
|
|
{
|
|
/** @var array<string,mixed> */
|
|
public static array $options = [];
|
|
/** @var array<string,array<int,array{cb:callable,priority:int,accepted_args:int,seq:int}>> */
|
|
public static array $filters = [];
|
|
public static int $next_seq = 0;
|
|
|
|
public static function reset(): void
|
|
{
|
|
self::$options = [];
|
|
self::$filters = [];
|
|
self::$next_seq = 0;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('apply_filters')) {
|
|
function apply_filters($tag, $value, ...$args) {
|
|
if (!isset(Cf7stgWpShimState::$filters[$tag])) {
|
|
return $value;
|
|
}
|
|
$callbacks = Cf7stgWpShimState::$filters[$tag];
|
|
usort($callbacks, static fn($a, $b) => ($a['priority'] <=> $b['priority']) ?: ($a['seq'] <=> $b['seq']));
|
|
foreach ($callbacks as $f) {
|
|
$cb_args = array_slice(array_merge([$value], $args), 0, $f['accepted_args']);
|
|
$value = call_user_func_array($f['cb'], $cb_args);
|
|
}
|
|
return $value;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('add_filter')) {
|
|
function add_filter($tag, $cb, $priority = 10, $accepted_args = 1) {
|
|
Cf7stgWpShimState::$filters[$tag][] = [
|
|
'cb' => $cb,
|
|
'priority' => (int)$priority,
|
|
'accepted_args' => (int)$accepted_args,
|
|
'seq' => Cf7stgWpShimState::$next_seq++,
|
|
];
|
|
return true;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('remove_all_filters')) {
|
|
function remove_all_filters($tag, $priority = false) {
|
|
if ($priority === false) {
|
|
unset(Cf7stgWpShimState::$filters[$tag]);
|
|
return true;
|
|
}
|
|
if (!isset(Cf7stgWpShimState::$filters[$tag])) {
|
|
return true;
|
|
}
|
|
Cf7stgWpShimState::$filters[$tag] = array_values(array_filter(
|
|
Cf7stgWpShimState::$filters[$tag],
|
|
static fn($f) => $f['priority'] !== (int)$priority
|
|
));
|
|
return true;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('add_action')) {
|
|
function add_action($tag, $cb, $priority = 10, $accepted_args = 1) {
|
|
return add_filter($tag, $cb, $priority, $accepted_args);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('do_action')) {
|
|
function do_action($tag, ...$args) {
|
|
apply_filters($tag, null, ...$args);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_option')) {
|
|
function get_option($key, $default = false) {
|
|
return Cf7stgWpShimState::$options[$key] ?? $default;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('update_option')) {
|
|
function update_option($key, $value) {
|
|
Cf7stgWpShimState::$options[$key] = $value;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('add_option')) {
|
|
function add_option($key, $value) {
|
|
if (array_key_exists($key, Cf7stgWpShimState::$options)) {
|
|
return false;
|
|
}
|
|
Cf7stgWpShimState::$options[$key] = $value;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('delete_option')) {
|
|
function delete_option($key) {
|
|
unset(Cf7stgWpShimState::$options[$key]);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('is_email')) {
|
|
function is_email($email) {
|
|
$email = (string)$email;
|
|
if ($email === '' || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
return false;
|
|
}
|
|
return $email;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('current_time')) {
|
|
function current_time($format) {
|
|
if ($format === 'mysql') return date('Y-m-d H:i:s');
|
|
return date($format);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('wp_date')) {
|
|
function wp_date($format, $timestamp = null) {
|
|
return date($format, $timestamp ?? time());
|
|
}
|
|
}
|
|
|
|
if (!function_exists('esc_html')) {
|
|
function esc_html($s) { return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); }
|
|
}
|
|
if (!function_exists('esc_url')) {
|
|
function esc_url($s) { return filter_var((string)$s, FILTER_SANITIZE_URL); }
|
|
}
|
|
if (!function_exists('wp_strip_all_tags')) {
|
|
function wp_strip_all_tags($s) { return trim(strip_tags((string)$s)); }
|
|
}
|
|
if (!function_exists('__')) {
|
|
function __($text) { return $text; }
|
|
}
|
|
if (!function_exists('wp_json_encode')) {
|
|
function wp_json_encode($v) { return json_encode($v, JSON_UNESCAPED_UNICODE); }
|
|
}
|