Need help? Check out our Support site, then


Capabilities in WP 2 / Create and Delete capabilities

  1. Hi there,

    one of the most anoying things in WP 2 are an missing out-of-the-box role editor (there is an plugin, but it is not perfect at all because of many weaknesses in the WP2 role/capabilitiy system - e.g. some capabilities are bound to a specific named role and not to the capability itself) - but much more i miss a finer control over the capabilities.

    I spend lots of time to find plugins for limiting categories or pages but i was not satisfied at all because (for example) "restrict pages" from Owen Winkler does not disable the creation of new pages - and that is not possible without modifying the code of a WP 2 admin component (page-new.php) because WP2 thinks that "edit" capabilities are also "create" capabilities - not really useful.

    A small hack for this (which works fine with WP 2.0.4) follows (it is an adaption of Owen Winklers "restrict_pages.php"):

    In "page-new.php" you have to modify the line that looks like:

    if ( current_user_can('edit_pages') ) {

    into
    if ( current_user_can('create_pages') ) {

    then you have to add the following script to your plugin folder (it should have the name "restrict_create_pages.php":

    <br /> <?php<br /> /*<br /> Plugin Name: Restrict Page Creation<br /> Description: Restricts users from creating Pages unless they have create pages capability<br /> Version: 0.1<br /> Author: Axel Napolitano<br /> Author URI: http://www.pro-rauchfrei.de<br /> Plugin URI:<br /> */</p> <p>class Restrict_Create_Pages<br /> {<br /> function Restrict_Create_Pages()<br /> {<br /> add_filter('user_has_cap', array(&$this, 'user_has_cap'), 10, 3);<br /> add_filter('capabilities_list', array(&$this, 'capabilities_list'));<br /> }</p> <p> function user_has_cap()<br /> {<br /> global $post, $current_user;<br /> $vargs = func_get_args();<br /> list($allcaps, $reqcaps, $args) = $vargs;</p> <p> if(($reqcaps[0] == 'create_pages') && $allcaps['create_pages'] == 1)<br /> {<br /> return $allcaps;<br /> }<br /> else if(($reqcaps[0] == 'create_pages') && $allcaps['create_pages'] != 1)<br /> {<br /> $allcaps = array();<br /> }<br /> else<br /> {<br /> return $allcaps;<br /> }<br /> }</p> <p> function capabilities_list($caplist)<br /> {<br /> $caplist[] = 'create_pages';<br /> return $caplist;<br /> }<br /> }</p> <p>$restrict_create_pages = new Restrict_Create_Pages();</p> <p>?><br />

    Warning

    Any user (also the admin-user) without the "create_pages" capability will loose the ability to create new pages. In case of an accident, you can safely rename or delete the plugin from your plugins folder to disable its functionality. It is best used with the installed role editor from Owen Winkler.

    Suggestion and Idea:

    • Extend the capability system. Add the capabilities "create" and "delete" to allow a finer control if neccessary.

    Thanks!

    Regards

    Rick Deckart

  2. ummm you're in the wrong forum if you're either self hosted or web hosted you need to be over here http://wordpress.org/support

  3. might be possible ... maybe i am to fast. "Ideas" seems to be a good place for an idea ;-) But maybe this "Ideas" forum is not for improvement stuff ... Forgive me, please !

  4. But maybe this "Ideas" forum is not for improvement stuff ...

    It is but we're talking different software though. :)

Topic Closed

This topic has been closed to new replies.

About this Topic