Skip to content

Commit

Permalink
Avoid accessing the $conf global directly
Browse files Browse the repository at this point in the history
This can cause errors if the configurations haven't been initialised
yet. On the suggestion of annda, I've added a getConf() method which
will load the configurations if they haven't been already.
  • Loading branch information
cmacmackin committed Dec 11, 2023
1 parent d2ce449 commit 78f02c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 12 additions & 0 deletions types/AbstractBaseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,18 @@ public function getLang($string)
return $this->hlp->getLang($string);
}

/**
* Convenience method to access plugin configurations
*
* @param string $string
* @return string
*/
public function getConf($string)
{
if (is_null($this->hlp)) $this->hlp = plugin_load('helper', 'struct');
return $this->hlp->getConf($string);
}

/**
* With what comparator should dynamic filters filter this type?
*
Expand Down
3 changes: 1 addition & 2 deletions types/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function handleAjax()
{
/** @var AuthPlugin $auth */
global $auth;
global $conf;
global $INPUT;
global $_SERVER;
global $USERINFO;
Expand All @@ -76,7 +75,7 @@ public function handleAjax()

if (
!auth_isMember(
$conf['plugin']['struct']['allow_username_autocomplete'],
$this->getConf('allow_username_autocomplete'),
$_SERVER['REMOTE_USER'],
(array) $USERINFO['grps']
)
Expand Down

0 comments on commit 78f02c8

Please sign in to comment.