2026-10-08 GLOBAL

This commit is contained in:
Dekart Deploy Bot 2026-10-08 12:42:33 +00:00
parent 356108a158
commit 17099d993e
2 changed files with 66 additions and 0 deletions

View File

@ -5198,6 +5198,7 @@ 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';
require_once __DIR__ . '/inc/cli-cf-import.php';
require_once __DIR__ . '/inc/css-minify.php';
require_once __DIR__ . '/inc/perf-css.php';

View File

@ -0,0 +1,65 @@
<?php
// WP-CLI: импорт Carbon Fields из JSON → theme options / мета поста
if (! defined('WP_CLI') || ! WP_CLI) {
return;
}
class Dekart_CF_Import {
/**
* Импорт значений Carbon Fields из JSON-файла.
*
* ## OPTIONS
*
* <file> Путь к JSON: {"field_name": value, ...}
* [--post=<id>] Писать как мета поста (carbon_set_post_meta) вместо опций темы.
* [--dry-run] Только показать, не писать.
*
* ## EXAMPLES
*
* wp dekart import-cf family.json
* wp dekart import-cf page.json --post=1190
*
* @when after_wp_load
*/
public function __invoke($args, $assoc_args) {
$file = isset($args[0]) ? (string) $args[0] : '';
if ($file === '' || ! is_readable($file)) {
WP_CLI::error('Файл не найден: ' . $file);
}
$data = json_decode((string) file_get_contents($file), true);
if (! is_array($data)) {
WP_CLI::error('Некорректный JSON: ожидается объект {"field": value}.');
}
$dry = isset($assoc_args['dry-run']);
$post = isset($assoc_args['post']) ? (int) $assoc_args['post'] : 0;
foreach ($data as $key => $val) {
if ($dry) {
WP_CLI::log('[dry] ' . $key . ' = ' . wp_json_encode($val, JSON_UNESCAPED_UNICODE));
continue;
}
if ($post) {
carbon_set_post_meta($post, $key, $val);
} else {
carbon_set_theme_option($key, $val);
}
WP_CLI::log('set ' . $key);
}
if ($dry) {
WP_CLI::success('dry-run: изменений не внесено');
return;
}
// верификация чтением
foreach (array_keys($data) as $key) {
$got = $post ? carbon_get_post_meta($post, $key) : carbon_get_theme_option($key);
WP_CLI::log('ok ' . $key . ' => ' . wp_json_encode($got, JSON_UNESCAPED_UNICODE));
}
WP_CLI::success($post ? ('обновлено мета поста #' . $post) : 'theme options обновлены');
}
}
WP_CLI::add_command('dekart import-cf', 'Dekart_CF_Import');