pairing = $pairing; } public function register_hooks(): void { add_action( 'admin_post_two_ua_release_guard_connect', array( $this, 'connect' ) ); add_action( 'admin_post_two_ua_release_guard_rotate', array( $this, 'rotate' ) ); add_action( 'admin_post_two_ua_release_guard_disconnect', array( $this, 'disconnect' ) ); } public function connect(): void { $this->authorize( 'connect' ); if ( '1' !== filter_input( INPUT_POST, 'two_ua_cloud_consent', FILTER_SANITIZE_NUMBER_INT ) ) { $this->redirect( 'consent_required' ); } try { $this->pairing->connect(); $this->redirect( 'connected' ); } catch ( ApiException $exception ) { $this->redirect( 'failed' ); } } public function rotate(): void { $this->authorize( 'rotate' ); try { $this->pairing->rotate_secret(); $this->redirect( 'rotated' ); } catch ( ApiException $exception ) { $this->redirect( 'failed' ); } } public function disconnect(): void { $this->authorize( 'disconnect' ); try { $this->pairing->disconnect(); $this->redirect( 'disconnected' ); } catch ( ApiException $exception ) { $this->redirect( 'failed' ); } } private function authorize( string $action ): void { if ( ! Capabilities::can_manage() ) { wp_die( esc_html__( 'You are not allowed to manage the 2UA connection.', '2ua-seo-release-guard' ) ); } check_admin_referer( 'two_ua_release_guard_' . $action ); } private function redirect( string $status ): void { $url = add_query_arg( 'two_ua_connection', $status, admin_url( 'options-general.php?page=two-ua-seo-release-guard' ) ); wp_safe_redirect( $url ); exit; } }