andieje
asked on
Wordpress guidance - how do you handle custom pages for different user roles
Hello
This is my optimal scenario. It is a nursery website with general information available to all members of the public. I'm ok with that bit
Then there is an staff section where stafff can login and add informtion about a pupil's progress thtat day
Then there is a parent section where parents can login and find informton about their children for that day.
I have seen that you can include a role based admin section as described here
http://www.paulund.co.uk/create-your-own-wordpress-login-page
My query is about the custom pages for the staff and parent sections. These pages woudl have to be written using php and wont just be part of some template. Can i add the new database tables that I need to the wordpress database? Can i use the wpdb databsae object with my new tables?
I am presuming the answers woudl be yes to these questions. Where would i put the php pages for the parent/staff section? Would they just be relative to public html?
Thanks in advance. I'm not really that comfortable wth wordpress
This is my optimal scenario. It is a nursery website with general information available to all members of the public. I'm ok with that bit
Then there is an staff section where stafff can login and add informtion about a pupil's progress thtat day
Then there is a parent section where parents can login and find informton about their children for that day.
I have seen that you can include a role based admin section as described here
http://www.paulund.co.uk/create-your-own-wordpress-login-page
My query is about the custom pages for the staff and parent sections. These pages woudl have to be written using php and wont just be part of some template. Can i add the new database tables that I need to the wordpress database? Can i use the wpdb databsae object with my new tables?
I am presuming the answers woudl be yes to these questions. Where would i put the php pages for the parent/staff section? Would they just be relative to public html?
Thanks in advance. I'm not really that comfortable wth wordpress
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
here are some examples of how it can be accomplished
//http://codex.wordpress.org/Roles_and_Capabilities
//http://codex.wordpress.org/Function_Reference/add_cap
//http://codex.wordpress.org/Function_Reference/current_user_can
$cap_array_custom_admin = array(
'delete_others_pages' => true,
'delete_others_posts' => true,
'delete_pages' => true,
'delete_posts' => true,
'delete_private_pages' => true,
'delete_private_posts' => true,
'delete_published_pages' => true,
'delete_published_posts' => true,
'edit_others_pages' => true,
'edit_others_posts' => true,
'edit_pages' => true,
'edit_posts' => true,
'edit_private_pages' => true,
'edit_private_posts' => true,
'edit_published_pages' => true,
'edit_published_posts' => true,
'manage_categories' => false,
'manage_links' => true,
'moderate_comments' => true,
'publish_pages' => true,
'publish_posts' => true,
'read' => true,
'read_private_pages' => true,
'read_private_posts' => true,
'unfiltered_html ' => false,
'upload_files' => true,
'allow_front_end_new_post_ submit' => true,
'allow_verified_user_comme nt' => true,
'allow_post_thumbs_up' => true,
'allow_post_social_media_s haring' => true,
'allow_verify_club_member_ reg' => true,
'allow_verify_club_staff_r eg' => true,
'allow_verify_public_reg' => true,
'allow_club_post_abuse_rep ort_notifi cation' => true,
'allow_approve_club_post' => true,
'allow_approve_public_post ' => true,
'allow_public_post_abuse_r eport_noti fication' => true,
'allow_set_feature_post' => true,
'allow_disable_account' => true,
'allow_approve_tag' => true,
'allow_add_new_custom_admi n' => true);
add_role('Custom_Admin', 'Custom Admin', $cap_array_custom_admin);
//change the capabilities to various other roles, create a user role without the ability to add new admins
//change the value in the array to false
$cap_array_custom_admin['a llow_add_n ew_custom_ admin'] = false;
//create the role
add_role('Custom_Admin_jr' , 'Custom Admin Junior', $cap_array_custom_admin);
//add a capability, add this to the array
add_role('Custom_Admin_spr ', 'Custom Admin Super', array_merge(array(
'allow_add_new_custom_admi n'=>true,
),$cap_array_custom_admin) );
// check the user role
function get_user_roles( $user_id ) {
$user_roles = [];
$user = get_userdata( $user_id );
$capabilities = $user->{$wpdb->prefix . 'capabilities'};
if ( !isset( $wp_roles ) ) {
$wp_roles = new WP_Roles();
foreach ( $wp_roles->role_names as $role => $name ) {
if ( array_key_exists( $role, $capabilities ) )
$user_roles[] = $role;
}
}
return $user_roles;
}
//check if the current user can do a soecfic capability
if (current_user_can( 'allow_add_new_custom_admi n' ) ){
// do action(s) allowable by users with this capability
}
//http://codex.wordpress.org/Roles_and_Capabilities
//http://codex.wordpress.org/Function_Reference/add_cap
//http://codex.wordpress.org/Function_Reference/current_user_can
$cap_array_custom_admin = array(
'delete_others_pages' => true,
'delete_others_posts' => true,
'delete_pages' => true,
'delete_posts' => true,
'delete_private_pages' => true,
'delete_private_posts' => true,
'delete_published_pages' => true,
'delete_published_posts' => true,
'edit_others_pages' => true,
'edit_others_posts' => true,
'edit_pages' => true,
'edit_posts' => true,
'edit_private_pages' => true,
'edit_private_posts' => true,
'edit_published_pages' => true,
'edit_published_posts' => true,
'manage_categories' => false,
'manage_links' => true,
'moderate_comments' => true,
'publish_pages' => true,
'publish_posts' => true,
'read' => true,
'read_private_pages' => true,
'read_private_posts' => true,
'unfiltered_html ' => false,
'upload_files' => true,
'allow_front_end_new_post_
'allow_verified_user_comme
'allow_post_thumbs_up' => true,
'allow_post_social_media_s
'allow_verify_club_member_
'allow_verify_club_staff_r
'allow_verify_public_reg' => true,
'allow_club_post_abuse_rep
'allow_approve_club_post' => true,
'allow_approve_public_post
'allow_public_post_abuse_r
'allow_set_feature_post' => true,
'allow_disable_account' => true,
'allow_approve_tag' => true,
'allow_add_new_custom_admi
add_role('Custom_Admin', 'Custom Admin', $cap_array_custom_admin);
//change the capabilities to various other roles, create a user role without the ability to add new admins
//change the value in the array to false
$cap_array_custom_admin['a
//create the role
add_role('Custom_Admin_jr'
//add a capability, add this to the array
add_role('Custom_Admin_spr
'allow_add_new_custom_admi
),$cap_array_custom_admin)
// check the user role
function get_user_roles( $user_id ) {
$user_roles = [];
$user = get_userdata( $user_id );
$capabilities = $user->{$wpdb->prefix . 'capabilities'};
if ( !isset( $wp_roles ) ) {
$wp_roles = new WP_Roles();
foreach ( $wp_roles->role_names as $role => $name ) {
if ( array_key_exists( $role, $capabilities ) )
$user_roles[] = $role;
}
}
return $user_roles;
}
//check if the current user can do a soecfic capability
if (current_user_can( 'allow_add_new_custom_admi
// do action(s) allowable by users with this capability
}
ASKER
Superb :)
ASKER