3324 posts
  • Provided great contribution to our forums
  • Nominated Community Superstar of the month
  • Helps us moderate the forums
  • Has been part of the Envato Community for over 5 years
+18 more
dtbaker 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

3324 posts
  • Provided great contribution to our forums
  • Nominated Community Superstar of the month
  • Helps us moderate the forums
  • Has been part of the Envato Community for over 5 years
+18 more
dtbaker 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;
}
1512 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+2 more
OriginalEXE says

Your variable name :P

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by