New answers tagged

0

With the wp_login hook the logged in user might not be set as the current user yet, so instead of using wp_get_current_user(), use the user object that's passed to the hook callback. Then you can be certain that you're setting the role on the correct user, rather than relying on the global state, which is unreliable. It is always preferable to use arguments ...


0

It is used to update the status of a user in the database. Used in core to mark a user as spam or "ham" (not spam) on multisite installs. Status 0 is Ham Status 1 is Spam Again, this will not work on single site installs. https://codex.wordpress.org/Function_Reference/update_user_status#Mark_a_User_as_Spam


0

If remove_menu_page doesn't work for you (it didn't for me) then instead of removing the menu, an alternative is to tell WordPress not to show the menu for the post type: function wpse28782_hide_menu_items() { if( !current_user_can( 'administrator' ) ) { $post_type = get_post_type_object( 'your_post_type'); if ($post_type) { $...


0

This is how to get an array of all the existing user roles, and the capabilities for each role, in WordPress. If you don’t want to print it to the screen, omit the last line. The $roles variable on line 2 will hold the array of users and capabilities so that you can use it however you need to. See below for an example of the returned array. global $wp_roles;...


0

After searching a lot over the web I found a solution, you can pass in the ids of categories you want to hide as an array, and then paste this in your functions.php file. All categories will be shown for administrators $exclude_array = array("5","6","7","1"); function hide_categories_for_specific_user( $exclusions, $args ){ if (!current_user_can('...


1

Although you could create another class of users, I'd just do the following: Change their password to something really strong and random Change their email address to an invalid value (or maybe a variation of yours) so they can't do a password reset. Maybe change their description/info to show that they are a 'past employee' or whatever generic/polite term ...


-1

WPBeginner has an article describing use of the "User Blocker". It sounds like just what you need. Good luck!


2

As @butlerblog reply stated, you should not use current_user_can to check against a role This notice is specifically added in the PHP documentation of has_cap function which is called by current_user_can While checking against a role in place of a capability is supported in part, this practice is discouraged as it may produce unreliable results. The ...


0

$POST = filter_var_array($_POST, FILTER_SANITIZE_STRING); $nome = $POST['nome']; $cognome = $POST['cognome']; $email = $POST['email']; $token = $POST['stripeToken']; $nickname = $nome . ' ' . $cognome; // Inserisce utente nel DB $user_data = [ 'user_login' => $nickname, 'user_pass' => wp_generate_password (), 'user_email' => $email,...


1

When using user_can() you pass it the user ID (or object) and the "capability" you want to check: $user_can = user_can( $user_id, 'edit_posts' ); The list of built in roles, and what capabilities they have, is available here. You can pass any of those to the function to determine if a user has that capability based on their role. However, that is only ...


1

"Add Role" isn't an option in WordPress, and never has been. If you want to add a role you'll need a plugin like User Role Editor or Members. If you want to add a role with code, you can do this with the add_role() function: add_role( 'member', 'Member', [ 'edit_posts' => true, ] ); Just be aware that roles are persistent, so ...


1

I have the same thing running on my website. Here is how I do do it... Only post author and commentor can view each others comments function restrict_comments( $comments , $post_id ){ global $post; $user = wp_get_current_user(); if($post->post_author == $user->ID){ return $comments; } foreach($comments as $comment){ if( $comment->...


Top 50 recent answers are included