2954 posts
  • Australia
  • Community Moderator
  • Elite Author
  • Author had a Free File of the Month
  • Most Wanted Bounty Winner
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Contributed a Blog Post
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+10 more
dtbaker Volunteer moderator says

Hey all,

I would like to create a “Wiki” on an existing WordPress site.

It would be great if users could register and then have create/edit permissions only on pages in a particular category or child of a particular parent page.

Created pages would be automatically added as sub pages to a parent page, or automatically added to a category.

Combined with a front end editor would be nice too.

Has anybody seen this so I don’t re-create the wheel?

There is a nice premium wiki plugin but I wanted to use core WP as much as possible.

Cheers,
dtbaker

2954 posts
  • Australia
  • Community Moderator
  • Elite Author
  • Author had a Free File of the Month
  • Most Wanted Bounty Winner
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Contributed a Blog Post
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+10 more
dtbaker Volunteer moderator says

Got my wiki (kinda!) working by granting every logged in user permission to edit all pages that are underneath the “documentation-wiki” parent page, but not other pages.

Phwoar!~

if(is_user_logged_in() && !current_user_can('administrator')){
    add_filter( 'user_has_cap', 'dtbaker_user_has_cap', 10, 3);
    add_filter( 'map_meta_cap', 'dtbaker_map_meta_cap', 10, 4 );
}
function dtbaker_user_has_cap($allcaps, $cap, $args){
$caps_to_give = array(
        'edit_others_pages',
        'edit_pages',
        'edit_page',
        'edit_published_pages',
        'publish_pages',
    );
    if( !in_array($args[0], $caps_to_give)){
        return $allcaps;
    }
    $allcaps[$cap[0]] = true;
    return $allcaps;
}
function dtbaker_wiki_is_page_a_wiki_page($page_id){
    $post = get_post( $page_id );
    $parents = get_post_ancestors( $post->ID );
    foreach($parents as $parentid){
        $parent = get_post( $parentid );
        if($parent->post_name == 'documentation-wiki'){
            return $post;
        }
    }
    return false;
}
function dtbaker_map_meta_cap( $caps, $cap, $user_id, $args ) {
    if ( 'edit_page' == $cap ) {
        $post = dtbaker_wiki_is_page_a_wiki_page($args[0]);
        if($post){
            $post_type = get_post_type_object( $post->post_type );
            $caps = array();
            $caps[] = $post_type->cap->edit_posts;
        }
    }
    return $caps;
}
1466 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
  • Croatia
OriginalEXE says

Your variable name :P

by
by
by
by
by
by