Restrict dashboard access for specific user roles to specific actions

This is how I ended up solving this issue. Originally I used this code for the link to delete an individual post: <?php if( !(get_post_status() == ‘trash’) ) : ?> <a class=”delete-post” onclick=”return confirm(‘Are you sure you wish to delete post: <?php echo get_the_title() ?>?’)”href=”https://wordpress.stackexchange.com/questions/78144/<?php echo get_delete_post_link( get_the_ID() ); ?>”>Delete</a> <?php endif; ?> After checking … Read more

How can I have different groups of editors only allowed to edit certain parent+subpages?

UPDATE – this is easy to do with the press permit plugin, I recommend it for any setup like this To get this working I had to do a couple of things: Default all pages/posts/categories ‘revisor’ (via Revisionary plugin) users to be restricted to ‘WP_Administrators’ Create a “User Group” for each department ie: ‘Conference Services … Read more

Let new user role to ‘edit_others_posts’ of other user role, not of its own type

First add capabilities to the roles like this add_action( ‘after_setup_theme’, ‘add_caps_to_custom_roles’ ); function add_caps_to_custom_roles() { $caps = array( ‘read_cpt’, ‘edit_cpt’, ‘edit_others_cpt’, ); $roles = array( get_role( ‘third_party’ ), get_role( ‘data_entry_operator’ ), ); foreach ($roles as $role) { foreach ($caps as $cap) { $role->add_cap( $cap ); } } } THEN /** * Helper function getting roles … Read more

Hide Specific User Page

I’m assuming you want to hide the author page on the site itself (and not in wp-admin). To do that, just create a new template file called author-{$id}.php, where {$id} is replaced by the ID of the author you want to hide. So if the author ID is 6, the template file should be called … Read more

Why is the reset password key missing in the reset password email?

The site’s original developer was using the reset_password_message filter and had either done it incorrectly or the core code has changed. The following function now works: function reset_password_message( $message, $key ) { if ( strpos($_POST[‘user_login’], ‘@’) ) { $user_data = get_user_by(’email’, trim($_POST[‘user_login’])); } else { $login = trim($_POST[‘user_login’]); $user_data = get_user_by(‘login’, $login); } $user_login = … Read more

Restrict access to specific users

This should do it. Place it in your theme’s functions.php or a plugin. function tst($a) { if (!current_user_can(‘edit_posts’)) { wp_die(‘You are not allowed to view this page’); } } add_filter(‘template_redirect’,’tst’); You can still get to the login page like normal by going to “/wp-login.php” or “/wp-admin”. Alternately, you could use wp_safe_redirect or wp_redirect instead of … Read more

Set default page for user account in admin

You set a custom url after rewrite from a login. A small example, usable in a template of the theme to login. <?php $redirect = esc_url( ‘your-url’ ); if ( ! is_user_logged_in() ) { $link = ‘<a href=”‘ . get_option( ‘siteurl’ ) . ‘/wp-login.php?redirect_to=’ . home_url( “https://wordpress.stackexchange.com/” ) . ‘”>’ . esc_attr__( ‘Login’, ‘documentation’ ) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)