Support » Fixing WordPress » add meta capabilites to current user?

  • I’d like to know how can I assign the current user the ability to edit a certain comment (or page/post, for that matter) if he doesn’t have it.

    So basically, I’m asking what would be the correct code for assigning meta capabilities to the current user.
    And for removing them, of course. I want to let the user edit a comment for a period of time (say 30 minutes). After that, it’s back to normal.

    Clarifications: I already know WP checks whether the user can edit the page/post when it allows editing of comments for that page/post, but I want to add another condition there, like in :

    if ( !(/ORGINAL CONDITION/) && !(current_user_can('edit_comment', $comment->comment_ID)) :
    //the edit comment stuff goes here...

    But first, I have to assign him that capability. How do I do that? From what I understand, I’d have to create a unique role, (perhaps based on comment ID, user_name and time), grant that role comment moderation capabilities, check if the comment_ID matches role name, as I don’t want the user to be able to edit any another comment, and after he’s done editing giving him his role back and delete the unique $role. Now that’s a bit complicated.
    Is there any other simpler way? Like…
    check if user has cap, add it if they don’t and remember they didn’t have it.
    add_cap($this_user, ‘edit_comment(comment->comment_ID)’, true);
    //edit the comment
    remove_cap(same $args as above); ? (if he didn’t have it in the first place)


  • The topic ‘add meta capabilites to current user?’ is closed to new replies.