Skip to content

Expiring users #17401

Answered by brandonkelly
bartrylant asked this question in Ideas
Discussion options

You must be logged in to vote

You could accomplish this by creating a “User Expirations” section, with a Users relation field.

Then create a plugin/module with the following code:

use craft\base\Event;
use craft\elements\Entry;
use craft\elements\User;
use craft\events\ModelEvent;
use craft\helpers\ElementHelper;

Event::on(Entry::class, Entry::EVENT_AFTER_SAVE, function (ModelEvent $event) {
    /** @var Entry $entry */
    $entry = $event->sender;
    
    if (
        !ElementHelper::isDraftOrRevision($entry) &&
        $entry->getSection()->handle === 'userExpirations' &&
        $entry->oldStatus === Entry::STATUS_LIVE &&
        $entry->getStatus() === Entry::STATUS_EXPIRED
    ) {
        /** @var User|null $us…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
user management 😇 features related to user management
2 participants