2026-10-06 GLOBAL
This commit is contained in:
parent
ed17593761
commit
e910bb61ef
@ -4691,6 +4691,7 @@ function dekart_flush_cache_page()
|
||||
require_once __DIR__ . '/inc/schema.php';
|
||||
require_once __DIR__ . '/inc/webmaster-recrawl.php';
|
||||
require_once __DIR__ . '/inc/js-snippet-comments.php';
|
||||
require_once __DIR__ . '/inc/cli-city-normalizer.php';
|
||||
|
||||
/**
|
||||
* Фильтр: замена H1 для страницы "Подготовка к школе" (ID 2)
|
||||
|
||||
193
wp-content/themes/dekart/inc/cli-city-normalizer.php
Normal file
193
wp-content/themes/dekart/inc/cli-city-normalizer.php
Normal file
@ -0,0 +1,193 @@
|
||||
<?php
|
||||
// WP-CLI: serialize-safe замена строки A → B в БД (posts, options, postmeta)
|
||||
if (! defined('WP_CLI') || ! WP_CLI) {
|
||||
return;
|
||||
}
|
||||
|
||||
class Dekart_City_Replace {
|
||||
|
||||
/** @var string */
|
||||
private $from = '';
|
||||
/** @var string */
|
||||
private $to = '';
|
||||
/** @var bool */
|
||||
private $dry = false;
|
||||
/** @var int */
|
||||
private $changed = 0;
|
||||
|
||||
/**
|
||||
* Замена строки в wp_posts (post_content, post_title), wp_options, wp_postmeta.
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* --from=<str> Искомая строка.
|
||||
* --to=<str> Строка замены.
|
||||
* [--dry-run] Только показать, ничего не писать.
|
||||
* [--posts=<0|1>] Обрабатывать wp_posts (по умолчанию 1).
|
||||
* [--options=<0|1>] Обрабатывать wp_options (по умолчанию 1).
|
||||
* [--postmeta=<0|1>] Обрабатывать wp_postmeta (по умолчанию 1).
|
||||
*
|
||||
* ## EXAMPLES
|
||||
*
|
||||
* wp dekart city-replace --from="Щелково" --to="Щёлково" --dry-run
|
||||
* wp dekart city-replace --from="Щелково" --to="Щёлково"
|
||||
*
|
||||
* @when after_wp_load
|
||||
*/
|
||||
public function __invoke($args, $assoc_args) {
|
||||
$this->from = isset($assoc_args['from']) ? (string) $assoc_args['from'] : '';
|
||||
$this->to = isset($assoc_args['to']) ? (string) $assoc_args['to'] : '';
|
||||
|
||||
if ('' === $this->from || '' === $this->to) {
|
||||
WP_CLI::error('Укажите --from=... и --to=...');
|
||||
}
|
||||
if ($this->from === $this->to) {
|
||||
WP_CLI::error('--from и --to совпадают — нечего менять');
|
||||
}
|
||||
$this->dry = isset($assoc_args['dry-run']);
|
||||
|
||||
$do_posts = ! isset($assoc_args['posts']) || '0' !== (string) $assoc_args['posts'];
|
||||
$do_opts = ! isset($assoc_args['options']) || '0' !== (string) $assoc_args['options'];
|
||||
$do_meta = ! isset($assoc_args['postmeta']) || '0' !== (string) $assoc_args['postmeta'];
|
||||
|
||||
WP_CLI::log(sprintf('%s «%s» → «%s»', $this->dry ? '[DRY-RUN]' : '[APPLY]', $this->from, $this->to));
|
||||
|
||||
if ($do_posts) {
|
||||
$this->process_posts();
|
||||
}
|
||||
if ($do_opts) {
|
||||
$this->process_options();
|
||||
}
|
||||
if ($do_meta) {
|
||||
$this->process_postmeta();
|
||||
}
|
||||
|
||||
WP_CLI::success(sprintf('%s. Изменено записей: %d', $this->dry ? 'DRY-RUN завершён' : 'Готово', $this->changed));
|
||||
}
|
||||
|
||||
private function process_posts(): void {
|
||||
global $wpdb;
|
||||
$table = $wpdb->posts;
|
||||
$like = '%' . $wpdb->esc_like($this->from) . '%';
|
||||
$rows = $wpdb->get_results($wpdb->prepare(
|
||||
"SELECT ID, post_content, post_title FROM {$table} WHERE post_content LIKE BINARY %s OR post_title LIKE BINARY %s",
|
||||
$like, $like
|
||||
));
|
||||
foreach ($rows as $row) {
|
||||
$new_content = $this->replace_value($row->post_content);
|
||||
$new_title = $this->replace_value($row->post_title);
|
||||
if ($new_content === $row->post_content && $new_title === $row->post_title) {
|
||||
continue;
|
||||
}
|
||||
$this->changed++;
|
||||
if ($this->dry) {
|
||||
WP_CLI::log(sprintf(' posts #%d %s', $row->ID, $new_title !== $row->post_title ? '(title)' : '(content)'));
|
||||
continue;
|
||||
}
|
||||
$wpdb->update($table, array('post_content' => $new_content, 'post_title' => $new_title), array('ID' => $row->ID));
|
||||
}
|
||||
}
|
||||
|
||||
private function process_options(): void {
|
||||
global $wpdb;
|
||||
$table = $wpdb->options;
|
||||
$like = '%' . $wpdb->esc_like($this->from) . '%';
|
||||
$rows = $wpdb->get_results($wpdb->prepare(
|
||||
"SELECT option_id, option_name, option_value FROM {$table} WHERE option_value LIKE BINARY %s",
|
||||
$like
|
||||
));
|
||||
foreach ($rows as $row) {
|
||||
$new = $this->replace_value($row->option_value);
|
||||
if ($new === $row->option_value) {
|
||||
continue;
|
||||
}
|
||||
$this->changed++;
|
||||
if ($this->dry) {
|
||||
WP_CLI::log(sprintf(' options %s', $row->option_name));
|
||||
continue;
|
||||
}
|
||||
$wpdb->update($table, array('option_value' => $new), array('option_id' => $row->option_id));
|
||||
}
|
||||
}
|
||||
|
||||
private function process_postmeta(): void {
|
||||
global $wpdb;
|
||||
$table = $wpdb->postmeta;
|
||||
$like = '%' . $wpdb->esc_like($this->from) . '%';
|
||||
$rows = $wpdb->get_results($wpdb->prepare(
|
||||
"SELECT meta_id, post_id, meta_key, meta_value FROM {$table} WHERE meta_value LIKE BINARY %s",
|
||||
$like
|
||||
));
|
||||
foreach ($rows as $row) {
|
||||
$new = $this->replace_value($row->meta_value);
|
||||
if ($new === $row->meta_value) {
|
||||
continue;
|
||||
}
|
||||
$this->changed++;
|
||||
if ($this->dry) {
|
||||
WP_CLI::log(sprintf(' postmeta #%d %s', $row->post_id, $row->meta_key));
|
||||
continue;
|
||||
}
|
||||
$wpdb->update($table, array('meta_value' => $new), array('meta_id' => $row->meta_id));
|
||||
}
|
||||
}
|
||||
|
||||
/** Значение: если serialized — распаковать/заменить/запаковать, иначе строка. */
|
||||
private function replace_value($value) {
|
||||
if (! is_string($value) || '' === $value) {
|
||||
return $value;
|
||||
}
|
||||
if (is_serialized($value)) {
|
||||
$data = @unserialize($value);
|
||||
if (false === $data && 'b:0;' !== $value) {
|
||||
return $this->replace_string($value);
|
||||
}
|
||||
return serialize($this->replace_recursive($data));
|
||||
}
|
||||
return $this->replace_string($value);
|
||||
}
|
||||
|
||||
/** Рекурсия по массивам/объектам, ключ @id пропускается. */
|
||||
private function replace_recursive($data) {
|
||||
if (is_array($data)) {
|
||||
$out = array();
|
||||
foreach ($data as $k => $v) {
|
||||
if ('@id' === $k) {
|
||||
$out[$k] = $v;
|
||||
continue;
|
||||
}
|
||||
$out[$k] = $this->replace_recursive($v);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
if (is_object($data)) {
|
||||
foreach (get_object_vars($data) as $k => $v) {
|
||||
if ('@id' === $k) {
|
||||
continue;
|
||||
}
|
||||
$data->$k = $this->replace_recursive($v);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
if (is_string($data)) {
|
||||
return $this->replace_string($data);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/** Строка: замена, но URL и @id не трогаем. */
|
||||
private function replace_string($s) {
|
||||
if (! is_string($s) || '' === $s || false === strpos($s, $this->from)) {
|
||||
return $s;
|
||||
}
|
||||
if (preg_match('#^\s*(https?:)?//#i', $s)) {
|
||||
return $s; // URL целиком
|
||||
}
|
||||
if (false !== strpos($s, '@id')) {
|
||||
return $s; // разметка @id
|
||||
}
|
||||
return str_replace($this->from, $this->to, $s);
|
||||
}
|
||||
}
|
||||
|
||||
WP_CLI::add_command('dekart city-replace', 'Dekart_City_Replace');
|
||||
@ -7,6 +7,7 @@ Template Name: Шаблон страницы Контакты
|
||||
get_header();
|
||||
$term = get_queried_object();
|
||||
$post_id = get_the_ID();
|
||||
$branch_city = get_option('branch_city') ?: carbon_get_theme_option('site_city');
|
||||
?>
|
||||
<main class="page contacts">
|
||||
<section class="content-main_block">
|
||||
@ -135,7 +136,7 @@ $post_id = get_the_ID();
|
||||
<div class="contacts_block-wrapper">
|
||||
<h2>Как добраться</h2>
|
||||
<p>Мы находимся в офисном центре «Сбербанк» рядом с гипермаркетом «Глобус» — <a style="text-decoration: underline;" href="<?php echo carbon_get_theme_option('site_map_link'); ?>" target="_blank" rel="noreferrer noopener"><strong>ссылка на карту</strong></a><br><br>
|
||||
По городу Щелково до остановки «Новый мост»: Автобусы или маршрутные такси 2, 25, 29, 35, 37, 40, 50, 361.<br><br>
|
||||
По городу <?php echo esc_html($branch_city); ?> до остановки «Новый мост»: Автобусы или маршрутные такси 2, 25, 29, 35, 37, 40, 50, 361.<br><br>
|
||||
Из города Фрязино до остановки «Новый мост»: Автобусы или маршрутное такси 49К, 20, 23, 29, 33, 35, 361, 37, 39, 50, 54<br><br>
|
||||
Адрес для координат <a style="text-decoration: underline;" href="<?php echo carbon_get_theme_option('site_map_link'); ?>"><strong>GPS: <?php echo carbon_get_theme_option('site_location'); ?></strong></a>
|
||||
</p>
|
||||
@ -162,7 +163,7 @@ $post_id = get_the_ID();
|
||||
<div class="contacts_block-wrapper">
|
||||
<div>Как добраться</div>
|
||||
<p>Мы находимся в офисном центре «Сбербанк» рядом с гипермаркетом «Глобус» — <a style="text-decoration: underline;" href="<?php echo carbon_get_theme_option('site_map_link'); ?>" target="_blank" rel="noreferrer noopener"><strong>ссылка на карту</strong></a><br><br>
|
||||
По городу Щелково до остановки «Новый мост»: Автобусы или маршрутные такси 2, 25, 29, 35, 37, 40, 50, 361.<br><br>
|
||||
По городу <?php echo esc_html($branch_city); ?> до остановки «Новый мост»: Автобусы или маршрутные такси 2, 25, 29, 35, 37, 40, 50, 361.<br><br>
|
||||
Из города Фрязино до остановки «Новый мост»: Автобусы или маршрутное такси 49К, 20, 23, 29, 33, 35, 361, 37, 39, 50, 54<br><br>
|
||||
Адрес для координат <a style="text-decoration: underline;" href="<?php echo esc_url(carbon_get_theme_option('site_map_link')); ?>"><strong>GPS: <?php echo esc_html(get_option('branch_coords') ?: carbon_get_theme_option('site_location')); ?></strong></a>
|
||||
</p>
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
if (! defined('ABSPATH')) exit;
|
||||
|
||||
$open_day_phone = get_option('branch_phone') ?: carbon_get_theme_option('site_phone') ?: '';
|
||||
$od_city = get_option('branch_city') ?: carbon_get_theme_option('site_city');
|
||||
$open_day_clean = $open_day_phone ? preg_replace('/[\s\-\–\(\)]/', '', $open_day_phone) : '';
|
||||
$od_post_id = get_the_ID();
|
||||
$od_photo_id = crb_get_post_meta($od_post_id, 'school_open_day_photo');
|
||||
@ -48,7 +49,7 @@ $open_day_points = array_values(array_filter((array) $open_day_points));
|
||||
<p class="school-open-day__footnote"><?php echo esc_html($od_footnote); ?></p>
|
||||
</div>
|
||||
<div class="school-open-day__visual">
|
||||
<img src="<?php echo esc_url($od_photo_url); ?>" alt="Начальные классы школы Декарт в Щелково" loading="lazy" width="550" height="390" class="school-open-day__photo">
|
||||
<img src="<?php echo esc_url($od_photo_url); ?>" alt="Начальные классы школы Декарт в <?php echo esc_attr($od_city); ?>" loading="lazy" width="550" height="390" class="school-open-day__photo">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user