• Resolved Dieter_Z

    (@dieter_z)


    Hello

    I wrote a little “plugin” for enhancing the user role “author”. He should be able to

    – see pages in admin area
    – edit pages which are published by himself
    – publish pages (authors normally are only allowed to publish posts)

    With these short lines of codes I got success and it works, but I’m not a developer and I’m not sure, if this is a real good solution. May please somebody tell me, if the following code ist correct for putting it into a plugin? Thanks a lot in advance.

    <?php
    $role_object = get_role( ‘author’ );
    $role_object->add_cap( ‘edit_pages’ );
    $role_object->add_cap( ‘publish_pages’ );
    $role_object->add_cap( ‘edit_published_pages’ );
    ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Your code is OK as far as it goes, but you don’t want this to run on every page request because the added capabilities are saved to the DB. You really only need the code to run once. This is often accomplished by running the code within a callback to a registered plugin activation hook.
    Function Reference/register activation hook

    Thread Starter Dieter_Z

    (@dieter_z)

    Hello and thanks for your answer. I just acivated the plugin for one time and after the changes in the DB were done I kicked it out. I am happy that this works, so authors may not work on “dangerous” pages ;-).
    I will have a look on your hint with the callback .. Thanks again!

    Thread Starter Dieter_Z

    (@dieter_z)

    Oh: forgot that it’s all good now … resolved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘add_cap for author role in a Plugin – is this correct code?’ is closed to new replies.