<?php

namespace GemBoards\hooks;

use GemBoards\Classes\Exception\GemboardsException;
use GemBoards\Utils\Helper;


if ( ! defined( 'ABSPATH' ) ) {
	exit;
} // if accessed directly, exit


class UserInvitation {

	public static function init() {
		$self = new self();
		add_action( 'gemboards/schedule/expired_new_user_invitation', [ $self, 'remove_invitation' ] );
	}

	public function remove_invitation( int $invitation_id ) {
		$invitation = Helper::get_user_invitation( $invitation_id );
		if ( ! $invitation ) {
			return;
		}

		try {
			$invitation->delete();
		} catch ( GemboardsException $e ) {
			Helper::error_log( $e->getMessage() );
		}
	}

}
