• Resolved Friday Next

    (@caseyfriday)


    I have built a site that will generate dynamic custom capabilities upon creation of a user, so that when a new user is created, they will have a page created with all of their information, and only that user can update their data.

    For instance, my username is ‘fridaynext’, so my custom capability is ‘fridaynext’, and I require ‘fridaynext’ in the S2Member meta box, on the page with my data. However, when I load that page in a private window (not logged in), I can still see all the data.

    Does the Custom Capability meta box NOT block everyone who does not have that custom capability from viewing the page? I’m reading that I might need to add a PHP statement to the page’s content to block the content to everyone except the owner, but I feel like that would defeat the purpose of the ccap meta box.

    TL;DR – Why is the custom capability meta box not applying the capability I enter?

    https://www.ads-software.com/plugins/s2member/

Viewing 9 replies - 1 through 9 (of 9 total)
  • … when I load that page in a private window …

    What does that mean? How exactly are you loading the page?

    Thread Starter Friday Next

    (@caseyfriday)

    That means loading an incognito window in Chrome, so that I’m not logged into the WordPress install.

    Have you tried accessing the page while logged out without being incognito? (The result matters, because it might help identify where the problem lies.)

    Thread Starter Friday Next

    (@caseyfriday)

    Yes, tried it logged out as well. If I put the custom capability in that meta box on the admin page, is it supposed to block that entire page from view to people without that custom capability?

    The other issue might be, I have no “the_content()” on that page, because it’s all built from PHP, using CPT and ACF, so I’m building all the content of the page myself.

    If I could grab the custom capability meta value that I’m entering in that box – with a PHP call – that would solve my problems, because then I could use ‘current_user can()’ with the custom capability, dynamically generated based on what page it is.

    I thought you might be doing something like that. The ccap is supposed to block the entire page from view to anyone without the ccap, but I suspect that what’s happening here is that it’s essentially protecting something that doesn’t exist.

    You can find the conditionals and constants you need for custom coding under API/Scripting. Otherwise I’d suggest you build a filter to get what you are creating to be returned by the_content().

    Thread Starter Friday Next

    (@caseyfriday)

    Do you know what the function call is to get the “Require Custom Capabilities” value I’ve typed in, on the page’s S2Member meta box? Like what is the meta_key for that value?

    No, but the s2Member Codex might help.

    Thread Starter Friday Next

    (@caseyfriday)

    I did not find any reference to a function like that in the Codex, which is why I’m asking here. Can someone from S2Member please respond?

    Thread Starter Friday Next

    (@caseyfriday)

    I’ve found how to set custom capabilities via PHP, on this page at S2Member:

    https://s2member.com/kb-article/rolescapabilities-via-php/

    Now I can trigger a capability set when a user is created, and also update the custom post type that is created for them with that same custom capability, so that every user has a unique page that only they can access.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Custom Capabilities not Working’ is closed to new replies.