I am wondering if someone can help me. I have developed a plugin that allows me to restrict the number of users registering on the site, but I would like to develop this further by restricting it to a particular user group, would anyone have any idea how i achieve this?

This is my code so far:

defined('_JEXEC') or die;


class plguserlimit extends JPlugin {

function __construct(&$subject, $config = array()) {
    parent::__construct($subject, $config);

public function onUserBeforeSave($user, $isnew, $new) {
    if ($isnew) {
        $limit   = $this->params->get('limit-text');
        $db    = JFactory::getDbo();
        $query = "select id from #__users";
        $num_rows = $db->getNumRows();
        if ($limit > $num_rows) {
            echo $erMsg = "Sorry but you have exceeded your allocated number of licenses.<BR><BR>Please press the back button on your browser to go back to the previous page.<BR><BR> If you wish to purchase more licences please contact customer support team ";
            JFactory::getApplication()->redirect(JURI::base(), $erMsg, 'error');

<extension type="plugin" version="3.0" group="user" method="upgrade">
<creationDate>June 2014</creationDate> 
<license>GNU General Public License version 2 or later; see LICENSE.txt</license> 
        this plugin is used for limiting user registering
    <filename plugin="registerlimit">registerlimit.php</filename> 
        <language tag="en-GB">en-GB.plg_user_regitesrlimit.ini</language> 
        <language tag="en-GB">en-GB.plg_user_regitesrlimit.sys.ini</language> 
            <fields name="params">
                <fieldset name="basic">
                    <field name="limit-text" type="text" default="" label="Enter user Limit" description="Set limit" /> 

For restricting registration as per user-group you need to use #_user_usergroup_map table for checking number of users in a particular group.

SELECT * FROM #_user_usergroup_map WHERE group_id = 'GROUP_ID';

Here replace your specific group_id value.

  • hi thanks for your reply, very helpful, i am not really fluent with XML in regards to calling from SQL, i would like to add a drop down menu in the plugin to be able to select the user group to restrict, how would i go about this please? Jun 30 '14 at 7:37
  • Use below code to display usergroups with xml <field name="usergroups" type="usergroup" description="UserGroup" label="Select Usergroup" size="10" />
    – Nick
    Jun 30 '14 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.