• current_user_can (”) have suddenly stopped working throughout my wordpress site.
    Which means that the site is not workings as intended since i based a lot of the site on ceatain user roles and capabilities.

    Anyone have had similar happen or can help in any way ?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    What do you mean by stopped working, is there an error? Is this regarding a plugin or theme?

    Thread Starter mtp12

    (@mtp12)

    i have used if statements in functions.php where if(current_user_can(‘read_private_posts’) example.

    This have worked great for some time. But suddenly today, it can no longer seem to regonize and user capability. So the if statement simply don’t work anymore.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    What does it return now?

    What makes you think that the function has stopped working, and not that the user has incorrect permissions? Have you checked that the user has the permissions you think they do. Try installing the User Role Editor plugin and checking that the users and roles have the correct permissions.

    Thread Starter mtp12

    (@mtp12)

    If i set up an if statement looking like this if(current_user_can(‘read_private_post’)){}
    It do the same thing for all users. Either it will come back true, or false.

    I have checked each user and see they have their capabilities still (using User Role Editor Plugin)
    I have also checked the database to check if the problem was it not saving the meta data on each user object. But that looked fine aswell.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    If it returns false then the function is still working and that is expected behaviour of the function: https://codex.ww.wp.xz.cn/Function_Reference/current_user_can (it returns boolean)

    Thread Starter mtp12

    (@mtp12)

    it returns the same whether the user object have the capability or not.

    So it returns true or false, depending on if i write with “!” or without, for both the user with the capability, and the user without.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I recommend you read the underlying code of the current_user_can function so that you truly understand what you want to do: https://core.trac.ww.wp.xz.cn/browser/tags/5.2.1/src/wp-includes/capabilities.php#L639

    Moderator bcworkz

    (@bcworkz)

    The result is filtered by “user_has_cap”. Some other plugin or your theme could be causing improper results.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘current_user_can(”) function has stopped working’ is closed to new replies.