Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9269303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:05:07+00:00 2026-06-18T15:05:07+00:00

I Have plugin called MyPlugin written by me. i have a yes or no

  • 0

I Have plugin called MyPlugin written by me. i have a yes or no radio button , If the option is yes means it should allow contributor to upload image and no means it should not allow.

This is the code to allow contributor to upload image

if ( current_user_can('contributor') && !current_user_can('upload_files') )
    add_action('admin_init', 'allow_contributor_uploads');
function allow_contributor_uploads() {
    $contributor = get_role('contributor');
    $contributor->add_cap('upload_files');
} 
// this is the code to remove if the capabilities if it is added

if ( current_user_can('contributor') && current_user_can('upload_files') )
    add_action('admin_init', 'remove_contributor_upload');
function remove_contributor_upload(){
    $con = get_role('contributor');
    $con->remove_cap('upload_files');
} 

i need a help where should i put this code in the plugin, i tried it but i got error as

Error in wp-includes/capabilities.php on line 1059
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:05:08+00:00Added an answer on June 18, 2026 at 3:05 pm

    You are calling functions that can’t be called before init(), so they are undefined (specifically, wp_get_current_user() is defined in wp-includes/pluggable.php and that isn’t loaded until after all plugins have been loaded). You need to rearrange your code to check user privileges after admin_init is called, e.g.

    add_action('admin_init', 'allow_contributor_uploads');
    function allow_contributor_uploads() {
        if ( current_user_can('contributor') && !current_user_can('upload_files') ) {
            $contributor = get_role('contributor');
            $contributor->add_cap('upload_files');
        }
    }
    // this is the code to remove if the capabilities if it is added
    
    add_action('admin_init', 'remove_contributor_upload');
    function remove_contributor_upload(){
        if ( current_user_can('contributor') && current_user_can('upload_files') ) {
            $con = get_role('contributor');
            $con->remove_cap('upload_files');
        }
    }
    

    NB: just solving your error problem here, have not looked at the logic of what you’re doing!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a jQuery plugin called waitForImages . It basically gives the ability
I have added a plugin called scrollpaper to a site I'm working on. The
I have a feature called foo, plugin called foo, and a single fragment foo.win32.x86.
I am using a jquery plugin from [ FilamentGroup ] called DateRangePicker. I have
I have a function called Colorbox (jQuery plugin) that takes a number of parameters
So, basically I have a plugin that I want called on an element if
I have a custom youtube plugin that adds an image to my tinyMCE editor
I have implemented a twitter login for my site, using a plugin called Simple
I'm using a jQuery plugin called InfiniteScroll ( https://github.com/paulirish/infinite-scroll ) and I have a
I have written a jQuery plugin below and would like to be able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.