Files
profile/inc/adfox_on.php
Profile Profile ed4d79b706 add files inc
2026-03-09 20:51:08 +03:00

74 lines
2.1 KiB
PHP

<?php
/**
* WP-CLI команды для управления рекламой
*/
if (!defined('ABSPATH') && !defined('WP_CLI')) {
exit;
}
class Ad_Manager_Commands {
/**
* Управление настройкой рекламы
*/
public function __invoke($args, $assoc_args) {
if (empty($args)) {
WP_CLI::error('Укажите действие: status, on, off, toggle');
}
list($action) = $args;
switch ($action) {
case 'status':
$this->show_status();
break;
case 'on':
$this->turn_on();
break;
case 'off':
$this->turn_off();
break;
case 'toggle':
$this->toggle();
break;
default:
WP_CLI::error("Неизвестная команда: {$action}. Используйте: status, on, off, toggle");
}
}
private function show_status() {
$show_ad = get_option('show_ad', 0);
$status = ((int)$show_ad === 1) ? '✅ включена' : '❌ выключена';
WP_CLI::line("Текущий статус рекламы: {$status}");
WP_CLI::line("Значение в базе: {$show_ad}");
}
private function turn_on() {
update_option('show_ad', 1);
WP_CLI::success('✅ Реклама включена');
$this->show_status();
}
private function turn_off() {
update_option('show_ad', 0);
WP_CLI::success('❌ Реклама выключена');
$this->show_status();
}
private function toggle() {
$current = get_option('show_ad', 0);
$new_value = ((int)$current === 1) ? 0 : 1;
$action = ($new_value === 1) ? '✅ включена' : '❌ выключена';
update_option('show_ad', $new_value);
WP_CLI::success("Реклама {$action}");
$this->show_status();
}
}
// Регистрируем команду
if (defined('WP_CLI') && WP_CLI) {
WP_CLI::add_command('ad', 'Ad_Manager_Commands');
}