I'm trying to block admin dashboard access using wp_redirect()
.
But the results of using current_user_can('edit_post')
are unexpected.
See my complete function below...
/**
* user constructor method.
*/
public function __construct()
{
// block admin dashboard access
add_action( 'admin_init', array( $this , 'block_admin_access' ) );
}
/**
* block admin dashboard access to users who cant edit posts
*/
public function block_admin_access () {
// if users cannot edit posts
if( ! current_user_can('edit_post') ) {
// redirect user to home page
wp_redirect( get_home_url() );
}
}
When I am logged in as an administrator user, this code above blocks me from the dashboard. Administrators can definately edit posts, so why does this code above redirect me away from the dashboard?
When I am using current_user_can('edit_post')
on the front end, the behaviour is normal.
Does anyone know why this could be?
edit_posts
plural?