3

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:

<?php
defined('_JEXEC') or die;

jimport('joomla.plugin.plugin');

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";
        $db->setQuery($query);
        $db->query();
        $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 ";
            die;
            JFactory::getApplication()->redirect(JURI::base(), $erMsg, 'error');
        }
    }
}
}


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

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? – user2513528 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.