Search This Blog

Thursday, December 13, 2012

Only show block to certain user

I wanted to hide my "Settings" block from all other users, except the admin role.

1)  I went into the file called:  mymoodleroot/blocks/settings/block_settings.php
2)  Inside two functions, I simply placed a role check at the beginning:

 function get_content() 
 {
    // only shows the settings block to admins
    global $USER, $CFG, $DB;
    if(!is_siteadmin($USER)) {return;}
        ...
}


function init() 
    {
    global $USER, $CFG, $DB;
    if(!is_siteadmin($USER)) {return;}

      ...
}



I'm sure that code could be modified to display to different roles and possibilities. This is just a simple example and it works!

No comments:

Post a Comment