Files
roi-theme/wp-content/plugins/wp-marketing-automations/includes/api/autonami/class-bwfan-api-toggle-automation-state.php
root a22573bf0b Commit inicial - WordPress Análisis de Precios Unitarios
- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 21:04:30 -06:00

60 lines
1.5 KiB
PHP
Executable File

<?php
class BWFAN_API_Toggle_Automation_State extends BWFAN_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::EDITABLE;
$this->route = '/automations/toggle-state';
}
public function default_args_values() {
$args = [
'state' => false,
'automation_id' => null,
];
return $args;
}
public function process_api_call() {
$state = $this->get_sanitized_arg( 'state', 'text_field' );
$automation_id = $this->get_sanitized_arg( 'automation_id', 'text_field' );
if ( empty( $automation_id ) ) {
return $this->error_response( 'Automation ID is missing', 'wp-marketing-automations' );
}
$automation['status'] = 2;
if ( 1 === absint( $state ) ) {
$automation['status'] = 1;
}
if ( 4 === absint( $state ) ) {
$result = BWFAN_Model_Automationmeta::insert_automation_meta_data( $automation_id, [
'v1_migrate' => true,
] );
} else {
$result = BWFAN_Core()->automations->toggle_state( $automation_id, $automation );
}
if ( false === $result ) {
return $this->error_response( 'Unable to update automation', 'wp-marketing-automations' );
}
$this->response_code = 200;
return $this->success_response( [], __( 'Automation updated', 'wp-marketing-automations' ) );
}
}
BWFAN_API_Loader::register( 'BWFAN_API_Toggle_Automation_State' );