File: /wordpress/plugins/wp-cloud-client/previous/src/Handler/SetDebugModeHandler.php
<?php
declare(strict_types=1);
namespace VPlugins\WPCloudClient\Handler;
use VPlugins\WPCloudClient\Debug\WpConfigEditor;
final class SetDebugModeHandler extends AbstractHandler {
/**
* Class constructor.
*
* @param WpConfigEditor $editor wp-config.php editor service.
*/
public function __construct(
private readonly WpConfigEditor $editor,
) {}
/**
* Return the action name.
*
* @return string Action name.
*/
public function action(): string {
return 'set_debug_mode';
}
/**
* Enable or disable WordPress debug mode in wp-config.php.
*
* On enable: WP_DEBUG=true, WP_DEBUG_LOG=true. On disable: both set to false.
* WP_DEBUG_DISPLAY is always forced to false on every call to avoid leaking
* error output to site visitors.
*
* @param array<string, mixed> $params Must contain 'enabled' (bool).
* @return array<string, mixed> Applied debug state.
*
* @throws \InvalidArgumentException If 'enabled' is missing or not boolean.
*/
public function execute( array $params ): array {
$this->requireParams( $params, 'enabled' );
if ( ! is_bool( $params['enabled'] ) ) {
throw new \InvalidArgumentException( "'enabled' must be a boolean." );
}
$enabled = $params['enabled'];
$this->editor->setConstant( 'WP_DEBUG', $enabled );
$this->editor->setConstant( 'WP_DEBUG_LOG', $enabled );
$this->editor->setConstant( 'WP_DEBUG_DISPLAY', false );
return [
'enabled' => $enabled,
'wp_debug' => $enabled,
'wp_debug_log' => $enabled,
'wp_debug_display' => false,
'message' => $enabled ? 'Debug mode enabled.' : 'Debug mode disabled.',
];
}
}