File: //wordpress/plugins/wp-cloud-client/1.1.7/src/Handler/SetLoginVisibilityHandler.php
<?php
declare(strict_types=1);
namespace VPlugins\WPCloudClient\Handler;
use VPlugins\WPCloudClient\Settings\SettingsRepository;
final class SetLoginVisibilityHandler extends AbstractHandler {
/**
* Class constructor.
*
* @param SettingsRepository $settings Settings repository.
*/
public function __construct(
private readonly SettingsRepository $settings,
) {}
/**
* Return the action name.
*
* @return string Action name.
*/
public function action(): string {
return 'set_login_visibility';
}
/**
* Expose or hide the wp-login.php page.
*
* Persists the choice to wpcc_settings so LoginPageGuard can redirect
* unauthenticated visitors away from wp-login.php when hidden. Mirrors the
* bootstrapper's WSP_EXPOSE_WP_LOGIN gate.
*
* @param array<string, mixed> $params Must contain 'expose' (bool).
* @return array<string, mixed> Applied login visibility state.
*
* @throws \InvalidArgumentException If 'expose' is missing or not a boolean value.
*/
public function execute( array $params ): array {
$this->requireParams( $params, 'expose' );
// FILTER_NULL_ON_FAILURE so unrecognised values (e.g. 2, "garbage") are
// rejected rather than silently coerced to false and hiding the login page.
$expose = filter_var( $params['expose'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE );
if ( null === $expose ) {
throw new \InvalidArgumentException( "'expose' must be a boolean value." );
}
$this->settings->setLoginExposed( $expose );
return [
'expose_login' => $expose,
'message' => $expose ? 'Login page exposed.' : 'Login page hidden.',
];
}
}