Users Field Plugin doesn't work

Hey there,
I wanted to include a checkbox with all users for a convenient way to add authors to articles and tried out users-field-plugin, but it seems to be broken …

In the backend, instead of a field, I get:
Undefined property: UsersField::$exclude

When I add an exlude rule to the blueprint, I get:
Undefined index: users

If I comment out the users line, I finally get the checkboxes with usernames and clearly the exclude for certain roles is working:

<?php
class UsersField extends CheckboxesField {
  public function options() {
    foreach(kirby()->site()->users() as $user) {
      if (is_array($this->exclude['roles']) && in_array($user->role(), $this->exclude['roles'])) continue;
      // if (is_array($this->exclude['users']) && in_array($user->username(), $this->exclude['users'])) continue;
        $options[$user->username()] =  $user;
    }
    return $options;
  }
}

But for a plugin that’s endorsed on getkirbyplugins.com, it seems too broken.

Yes, there’s a check missing if the option is set. If you set the exclude options, it works as expected but fails if you don’t.

getkirby-plugins.com is not an official Kirby site. But even if it was, we can’t possibly test all plugins or give any guarantees that the code base is any good.

Sure, just wanted to justify that I tried to solve it through forum instead of github. Sorry for any inconveniance!

No problem, I’ve seen you have already created an issue on GitHub. But there hasn’t been any activity in the repo for a very long time. Quick fix:

<?php

class UsersField extends CheckboxesField {

  public function options() {
    foreach(kirby()->site()->users() as $user) {
      if (isset($this->exclude['roles']) && is_array($this->exclude['roles']) && in_array($user->role(), $this->exclude['roles'])) continue;
      if (isset($this->exclude['users']) && is_array($this->exclude['users']) && in_array($user->username(), $this->exclude['users'])) continue;
        $options[$user->username()] =  $user;
    }
    return $options;
  }

}

An alternative would be to use the Controlled List plugin: https://github.com/rasteiner/controlledlist