• Hi!
    I create plugin with custom post type and new user role.

    This role is only to have access to the new post type, so I used add_cap() to determine what the user can and cannot do.

    Unfortunately the page returns an error:
    Fatal error: Uncaught Error: Call to a member function add_cap() on null

    I checked with the database. There is no record of wp_user_roles in the wp_options table.

    I try to create such a row with an empty option_value field, but the error is still displayed. I copy the contents of option_value field from another side, but nothing changes.

    The page is not a multisite

Viewing 1 replies (of 1 total)
  • The error is saying that you are trying to use a function that is in a class without a class. https://developer.www.ads-software.com/?s=add_cap
    add_cap() is a member function, either a WP_User object or a WP_Role object or a WP_Roles object is needed before you can call it.
    This has nothing to do with the database, and everything to do with your code flow. You have to get the user or role first, and then call add_cap() on it.

Viewing 1 replies (of 1 total)
  • The topic ‘Call to a member function add_cap() in single site (not multi)’ is closed to new replies.