• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Damien Carbery - Website Development

Getting You Online & Keeping You There

Getting You Online & Keeping You There Get Started
  • Home
  • Services
  • Maintenance Plans
  • Portfolio
  • Blog
  • About Me
  • Contact
You are here: Home / Website Development / Add capability to a specific user

Add capability to a specific user

Published: June 15, 2020

Add 'manage_options' capability to an non-admin user.

I am working on a site that uses the WP2Static plugin that creates a static html version of the site. It requires that the user has the ‘manage_options‘ capability to access it. Generally only administrators have this. I want to allow additional users without having to install the User Role Editor plugin.

Permanent change

If I use the add_cap() to add a capability to a user then it is stored in the database and is not easily removed (I tried using remove_cap() but it didn’t change). I had to install User Role Editor to undo the change!

On the fly

The other option is to use the ‘user_has_cap’ filter. This filter will be executed a lot so the code should be as lean as possible and exit as early a possible.

In my code it checks whether the ‘manage_options’ capability is being tested before checking for the current user ID and whether it matches the user I want to give the privilege to .

The code

It might be possible to improve the code e.g. exclude the is_user_logged_in() and wp_get_current_user() checks, because the ‘user_has_cap’ docs say that the user ID can be in the $args parameter.

Related Posts

Debugging – Figuring It Out Yourself

Learn how to investigate and fix front and back end WordPress issues. Use browser tools and the Query Monitor plugin to help locate the problem.

How to use my code snippets

My code snippets are presented as small, single file plugins that are easy to use - you just upload and activate.

Shortcode for Contact Form 7 Dynamic Text Extension

CF7DTE is great but sometimes you need a custom shortcode to get product info into the form.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Blog Categories

  • Being Green
  • Food
  • Grammar
  • Just Strange
  • Laziness
  • Personal
  • Portfolio
  • Race Reports
  • Shudder
  • Typo
  • Website Development
  • WooCommerce Tips
  • Facebook
  • Twitter

Copyright © 2013–2023 Damien Carbery · Using Genesis Framework · Privacy Policy