Working …
This value you provided is not a number. Please try again.
This value you provided is not an integer. Please try again.
The value entered is not a valid Vanderbilt Medical Record Number (i.e. 4- to 9-digit number, excluding leading zeros). Please try again.
The value you provided must be within the suggested range
The value you provided is outside the suggested range
This value is admissible, but you may wish to double check it.
The value entered must be a time value in the following format HH:MM within the range 00:00-23:59 (e.g., 04:32 or 23:19).
This field must be a 5 or 9 digit U.S. ZIP Code (like 94043). Please re-enter it now.
This field must be a 10 digit U.S. phone number (like 415 555 1212). Please re-enter it now.
This field must be a valid email address (like joe@user.com). Please re-enter it now.
The value you provided could not be validated because it does not follow the expected format. Please try again.
Required format:
REDCap Logo
Plugins, Hooks, & External Modules
Developer methods for
Plugins, Hooks, & External Modules
Hook functions

REDCap Developer Tools:
Documentation for Plugins, Hooks, & External Modules

REDCap Version 14.9.1
redcap_user_rights
(REDCap >= 5.11.0)
redcap_user_rights — Allows custom actions to be performed on the User Rights page of every project
Description
void redcap_user_rights ( int $project_id )
Allows custom actions to be performed on the User Rights page of every project. You may utilize this hook to 1) perform back-end operations, such as adding or modifying data in database tables, which can be done when the page loads or when triggered by a user action on the page via JavaScript, or 2) output custom HTML, JavaScript, and/or CSS to modify the current page in any way desired.
Location of Execution
The function is executed at the very bottom of User Rights page of every project. Anything output by the hook (such as HTML) will be displayed directly beneath the table of users/roles on the page.
Return Values
Nothing. Your function does not need to return anything.
Examples
Example #1:
This example demonstrates how to perform a specific operation on the User Rights page of every project, in which some HTML is output to the page and then manipulated using JavaScript/jQuery to move it to a different location on the page. This specific example shows how to add a box of yellow text on the page and then move it so that it appears directly beneath the instructional text on the page.
function redcap_user_rights()
{
    // Output a div containing a special announcement onto the page
    print  '<div class="yellow" id="my_custom_user_rights_div">
                Special announcement text to display right below the instructional text
                on every User Rights page.
            </div>';

    // Use JavaScript/jQuery to move our div right below the instructional text
    print  "<script type='text/javascript'>
            $(document).ready(function(){
                // Move our div right above the table listing all the users/roles
                $( 'div#user_rights_roles_table_parent' ).before( $('div#my_custom_user_rights_div') );
            });
            </script>";
}
Example #2:
This example shows a simple way of performing project-specific actions using the $project_id parameter. NOTE: This particular method is not as clean or as easy to maintain for many projects at once. See the next example for a better way to implement project-specific actions for many projects.
function redcap_user_rights($project_id)
{
    // Perform certain actions for specific projects (using "switch" or "if" statements).
    switch ($project_id) {

        // Perform operations for project_id 212
        case 212:
            // do something specific for this project ...
            break;

        // Perform operations for project_id 4775
        case 4775:
            // do something specific for this project ...
            break;

        // ...
    }
}
Example #3:
A much more manageable way to perform project-specific operations for many projects at once is to create a directory structure where each project has its own subdirectory under the main Hooks directory (e.g., named "redcap/hooks/pid{$project_id}/redcap_user_rights.php"). This allows the code for each project to be sandboxed and separated and also makes it more manageable to utilize other files (e.g., PHP, HTML, CSS, and/or JavaScript files) that you can keep in the project's subdirectory (i.e., "pid{$project_id}") in the Hooks folder. Then the designated project handler PHP script can utilize any of the parameters passed in the function to perform actions specific to each project. NOTE: This example assumes that the "hooks" sub-directory is located in the same directory as the PHP file containing the Hook functions.
function redcap_user_rights($project_id)
{
    // Set the full path of the project handler PHP script located inside the
    // project-specific sub-folder, which itself exists in the main Hooks folder.
    $project_handler_script = dirname(__FILE__) . "/hooks/pid{$project_id}/redcap_user_rights.php";

    // Check if the project handler PHP script exists for this project, and if so,
    // then "include" the script to execute it. If not, do nothing.
    if (file_exists($project_handler_script)) include $project_handler_script;
}
REDCap 14.9.1 - © 2024 Vanderbilt University