sinanisler logo

Add Student User Role, WordPress Roles

Function to add a new user role named “Student” This function creates a new user role with minimal capabilities, mainly ‘read’.

It is hooked to the WordPress ‘init’ action, so it runs during WordPress’s initialization process.

/**
 * Function to add a new user role named "Student"
 * This function creates a new user role with minimal capabilities, mainly 'read'.
 * It is hooked to the WordPress 'init' action, so it runs during WordPress's initialization process.
 */
function add_student_user_role() {
    // Add a new user role with the name 'Student'
    // The 'read' capability is a minimal capability that can be assigned
    add_role('student', 'student', array('read' => true));
}

// Hook the function to WordPress 'init'
add_action('init', 'add_student_user_role');

By the way, if you’re looking to restrict access to certain sections of your pages or sites to specific user roles, this plugin could be very useful;

Leave the first comment