WordPress.org

Support

Support » How-To and Troubleshooting » sub-page capability

sub-page capability

  • Two questions:

    1. How can I create capability for sub-categories and sub-pages. Is it enough just to add something like the following or I need to do more? Were can I find a list for this kind of meta.

    publish_sub_page
    edit_sub_page
    edit_published_sub_page
    delete_sub_page

    2. There is a feature in the screen shots that shows how to copy existing capabilities to a new role. there is no such window in the latest version of the pluging.

    Appreciate your concern.

Viewing 15 replies - 1 through 15 (of 19 total)
  • 1. It is not enough just create capability. All capabilities are checked by WordPress in its core code directly, like this

    if (!$current_user_can('edit_post') {
      echo 'you have not permission to edit posts';
      return;
    }

    Thus, if you create new capability it is your responsibility to check if user has it (in your theme or plugin code)

    2. What screen-shot number do you write about? There is no functionality to copy one role content (capabilities) to another in URE plugin for this moment. If it could be useful, I can consider to add such function.

    Thanks for the reply.

    1. Is this code you mentioned all I need to create a new capability or there is a How to instructions to follow creating a new role? Of course for users like me who are not very skilled can be a challenge creating new roles.

    2. Ok, it seems I looked at Capability Manager’s copy feature (screenshot 2) instead. But the feature could be useful if a user intends to choose an existing capability/role, copy to a new one with a new name and edit it afterward to minimize mistakes. Otherwise, a user has to write down everything for the base role and fill out the check boxes.

    3. Possible bug! When I deselect comment mediation, a user still can moderate! Do I have to do anything else?

    Appreciate your concern.

    I made a typo in code snippet above: ‘edit_posts’ should be there instead of ‘edit_post’.
    1. Creating new role is not so difficult if you intend to use just standard WordPress capabilities. You can modify existing role or create new one and fill it with capabilities according your needs. Just make and see what will be.
    If you need to realize something new, then you need to find the right place where to insert your capability checking code. Modifying core WordPress files is not the good practice as you will lose your changes every time you install next WordPress update. There are so called hooks (filters and actions) in WordPress, which allows to add new functionality to core WordPress code without changing its core code.
    I suppose that it is difficult task to realize separate capabilities checking for subpages as there is no separate type for that. Subpage has the same type as the page, that is ‘page’. ‘subpage’ is the sign of hierarchy structure only. May be I’m wrong, let me know if such :).
    2. Thanks for the valuable idea I will add this feature to the next update.
    3. Could you show me screenshot of the role you modified or send its capabilities list in order I can check at test site?

    Thanks again for your feedback.

    1. Sub-page publish capability: A user could have capability to publish/edit sub-pages, if and only if, he has selected a parent page he already has access to. Otherwise, he would be denied to publish/edit the page. I think, this way could work and it shouldn’t be necessary to hard code WP files.

    2. Thanks for your plan.
    3. I actually just selected same capabilities as author/editor for a new role and unchecked Comment Moderation. I tested and the result was that Moderation did not applied. Consequently, when logged in, I could see and moderate regardless of role (subscriber is exception)!
    (I’ll try to send you screenshot by e-mail)

    I tested the roles for s2Member different levels. Default capabilities are set to subscriber for each level.

    Appreciate it!

    I tried to find out how I can send you the screenshot without luck. I could not find any email at your site either. A contact form at your site does not allow file uploads.
    Please let me know how I can send you the screenshot if needed.

    Thanks in advance.

    You are welcome to send me the screenshot.
    I don’t expose my email to the Internet resources to not catch spam.
    You could send me a message via shinephp.com contact form and get my answer to your email. My email address consists of my name ‘vladimir’ and my domain ‘shinephp.com’.

    Thanks! I did sent it yesterday. Please let me know about the outcome 🙂

    Excuse me for delay with reply.
    It seems that WordPress allows moderate comments for post not only owner of ‘moderate_comments’ capability, but to the user who can edit that post, that is ‘editor’ and ‘administrator’ are in the list of persons with such moderation power.
    Quote from line 42 of wp-admin/edit-comments.php:

    foreach ( $comment_ids as $comment_id ) { // Check the permissions on each
    	if ( !current_user_can( 'edit_comment', $comment_id ) )
    		continue;
    
    	switch ( $doaction ) {
    		case 'approve' :

    and ‘edit_comment’ is mapped to ‘edit_posts’ at the
    wp-admin/includes/capabilities.php – map_meta_cap(), look to lines 954-959:

    case 'edit_comment':
    	$comment = get_comment( $args[0] );
    	$post = get_post( $comment->comment_post_ID );
    	$post_type_object = get_post_type_object( $post->post_type );
    
    	$caps = map_meta_cap( $post_type_object->cap->edit_post, $user_id, $post->ID );

    Thank you Vladimir,

    So just to summarize it, you mean that it’s not possible to restrict moderation for a user who has capability to edit a post?

    Is there any workaround to restrict moderation capability anyway?

    The simplest way is edit /wp-admin/edit-comments.php at line 11:

    if ( !current_user_can('edit_posts') )
    	wp_die(__('Cheatin’ uh?'));

    and change ‘edit_posts’ to ‘moderate_comments’. This way you can prohibit users without ‘moderate_comments’ capability even open comments list.
    The negative side is that you should hold this modification in your head and repeat this step after every WordPress update install.

    I tried to find how to achieve this via WordPress hooks, but with a half success only. It is possible to hide user interface part: bulk actions, moderation links from user without moderate_comments permission, but this functionality will be still available through direct link call if you type it in the browser.
    It seems that there is no any hook we can use to block moderation action this way without editing core WordPress files :(.

    To get more details on subject read this post

    Limit comments moderation

    Thank you very much for your reply.

    However, your solution seems logical. I assume that it should hide the moderation buttons/links when using your plugin with unchecked Moderation Capability. (Of course, I’m aware of modifications to be done in functions.php, according to your article).

    Please let me see if I can make it work.

    Thanks again!
    Cheers

    Just an updated question!

    According to the user level capabilities, moderation is not available for user levels 0-3. If user Levels were finally deprecated in WordPress 3.0, how does this work in your plugin? Are these levels activated in the plugin or just out-dated and not applicable?

    Read a note at the begin of the same page:
    “Note: User Levels were introduced in WordPress 1.5, they were replaced by Roles and Capabilities in WordPress 2.0, and were finally deprecated in WordPress 3.0”.

    Thus, user levels were deprecated since WordPress 3.0 and we can ignore them if we don’t use some out-dated plugin or theme.

    Of course, I have read that. Just wondered if they were functional through the plugin because the check boxes are selectable.
    Thanks

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘sub-page capability’ is closed to new replies.
Skip to toolbar