Groups and subgroups for permission

First you need to make group and subgroup. You can use wordpress existing User Role or you can make custom user role (group) by own. Members is a nice plugin to create custom role. For example your main group is “Group1” and subgroup is “Subgroup1”. First you need to check current user role (Group of … Read more

How to make current user’s avatar + display name link to their profile?

Use get_the_author_link() or get_the_author_meta(‘user_url’, $user_id). Your code would become something like: $author_link = get_the_author_link(); $header .= ‘<div><a href=”‘. $author_link . ‘”>’ .get_avatar($user_ID, 64).'</a></div>’; $header .= ‘<div><strong><a href=”‘ . $author_link . ‘”>’ . __(“”, “front-end-pm”).’ ‘. fep_get_userdata($user_ID, ‘display_name’, ‘id’) .'</a></strong>’; Watch out with the quotes though, your code seems to use double quotes, I tried to … Read more

Show site content based on user role

You have errors in the code First, you are using current_user_can() function the wrong way. It has two parameters — $capability and $object_id. You don’t need the latter one, so, in your case: current_user_can(‘subscriber’) In my opinion, it’s better to use capability instead of user role in this function. For example, subscribers can’t edit posts, … Read more

Register new user, assign custom role then send email

TO really fit your needs, I think it’s better to rewrite some part of wp_insert_user() function, some part can interrest you $user_email = apply_filters( ‘pre_user_email’, $raw_user_email ); And : $illegal_logins = (array) apply_filters( ‘illegal_user_logins’, array() ); if ( in_array( strtolower( $user_login ), array_map( ‘strtolower’, $illegal_logins ) ) ) { return new WP_Error( ‘invalid_username’, __( ‘Sorry, … Read more

Redirect user to login if not logged in, on specific pages

You can do it like this in admin section- add_action( ‘admin_init’, ‘redirect_non_logged_users_to_specific_page’ ); function redirect_non_logged_users_to_specific_page() { if ( !is_user_logged_in() && is_page(‘add page slug or i.d here’) && $_SERVER[‘PHP_SELF’] != ‘/wp-admin/admin-ajax.php’ ) { wp_redirect( ‘http://www.example.dev/page/’ ); exit; } And for frontend- add_action( ‘template_redirect’, ‘redirect_to_specific_page’ ); function redirect_to_specific_page() { if ( is_page(‘slug’) && ! is_user_logged_in() ) { … Read more

How can I link to the author’s page

I depends on whether you want the URL to the authors posts: ‘<a href=”‘.get_author_posts_url( $user->ID ).'”>user posts url</a>’ https://codex.wordpress.org/Function_Reference/get_author_posts_url Or the url to edit the user: ‘<a href=”‘.get_edit_user_link( $user->ID ).'”>edit user url</a>’ https://codex.wordpress.org/Function_Reference/get_edit_user_link

WordPress Multisite Add User

Ok, so this isn’t possible to do by default. As I already had a hook for wpmu_activate_blog() I just created another with a lower priority which will be fired after. This function also has the 2 parameters I need. So upon activation of the account I simply remove Admin role and set a new role … Read more