New answers tagged user-roles
0
User Role Editor plugin handles multiple roles for a user:
http://wordpress.org/plugins/user-role-editor
Once installed, Users > under each user is Capabilities option.
URE treats the first WP role as "primary role" and allows you to add "other roles".
1
Check this plugin. I've used it and it's quite versatile regarding user roles and user capabilities.
You can also add conditional statements in your php files, like this:
if (!current_user_can('some_capability_you_added')) {
echo "You don't have permission for it!";
return;
}
You can output that sentence or nothing at all.
0
You can detect the user from where it comes.like ( for google)
<?php
if (strpos($_SERVER[HTTP_REFERER], "google") == true) {
echo "Hello Google User!";
}
?>
so try it
<?php if (current_user_can(‘subscriber’) || strpos($_SERVER[HTTP_REFERER], "google") == true) { ?>
[content here]
<?php } ?>
Important Links
wp get referer
1
You could also do this,
function mod_redirect_subscriber_delete($user_id) {
$user = get_user_by('id', $user_id);
$role = $user->roles[0];
if ($role == 'subscriber') {
add_action("deleted_user", function(){
wp_redirect( admin_url('/index.php') );
exit;
});
}
}
add_action("delete_user", "mod_redirect_subscriber_delete");
...
1
a) delete_user hook:
Here is one idea:
Add this into your code to delete the user:
remove_action("delete_user", "mod_redirect_subscriber_delete");
wp_delete_user($user_id);
where we remove the action callback to prevent it calling it self again.
So your code becomes:
function mod_redirect_subscriber_delete($user_id) {
$user = get_user_by('id', ...
1
The "Contributor" role has very little access to anything on the back end but can created posts.
delete_posts
edit_posts
read
http://codex.wordpress.org/Roles_and_Capabilities#Contributor
For comparison, an ordinary "Subscriber" has the last of the three, so "Contributor" has only two extra capabilities.
I am not quite sure what "access ...
1
Users roles are changed by the WP_User object firing the set_role() function. At the end of that function on line 815 of wp-includes/capabilities.php there is an action to hook to: do_action( 'set_user_role', $this->ID, $role );
So, in your functions.php or in a plugin, you can grab that data as the hook fires after the user capability update, and ...
2
You can add actions to the set_user_role hook:
add_action( 'set_user_role', 'wpse98904_remove_demoted_user_posts', 10, 2 );
function wpse98904_remove_demoted_user_posts( $demoted_author_id, $role ) {
if( 'subscriber' == $role ) {
// In here you'd search for all the posts by the user
$args = array(
'numberposts' => ...
1
Filter the 'comments_open' check. It happens inside of the function with the same name, and that function is called in a theme usually like this:
comments_open() and comment_form(
array (
'comment_notes_after' => ''
)
);
This is how the filter works:
add_filter( 'comments_open', 'wpse_98775_comment_check', 10, 2 );
function ...
0
According to register_post_type() documentation capability_type argument is used to construct capabilities.
I think since you are customizing it for the post type, its capabilities requirements won't be formed like read_post but like read_an_group.
0
s_ha_dum, that was it. The WPMU Membership plugin was breaking it. It was odd because I tried configuring the access levels, but could not get it to work. So I just turned it off :)
1
This may be similar to what you are looking for, it doesn't force a category, but doesn't let the user submit the new post unless at least one category is selected
This solution requires jQuery, but with little modification can be ported to plain JavaScript
//intercept the "update" or "publish" button
$("#post").submit(function(e){
//grab the GET query ...
2
On the profile page exists a global variable $profileuser. The member $profileuser->roles is an array of all roles for that user.
<?php # -*- coding: utf-8 -*-
// Plugin Name: personal_options
add_action( 'personal_options', 'print_user_roles');
function print_user_roles()
{
global $profileuser;
print '<pre>$profileuser->roles = '
...
0
Well.. I see no code... so I don't know if you created the custom post type yourself, or used a plugin. I'm assuming you created the custom post type in functions.php. In there you can have an if statement to check if the user has certain capabilities.
<?php current_user_can( $capability, $args ); ?>
It would really help if you could post some code, ...
Top 50 recent answers are included