1

Contributors can create post drafts but not publish. I'd like to add the same permission concept but to Pages. That is, can I allow a Contributor to create a page draft only to have an Editor/Admin to later approve or reject?

From this question, I see that I can hook into the action new_role_edit_posts. Is there an equivalent new_role_edit_pages?

How would you go about this?

2

How would you go about this?

I see this is an old question and that you found a solution with an existing plugin. However, since this is a development StackExchange, it's probably better if there's an answer that explains how to accomplish the stated goals without the need for a third-party plugin.

Written Answer

WordPress stores capabilities in the database. Therefore, what we want is a plugin that will add the edit_pages capability to the contributor role upon plugin activation. For completeness, the plugin should remove the capability upon deactivation.

Coded Answer

/**
 * Plugin Name: WPSE 230940
 */

//* Add activation hook
register_activation_hook( __FILE__ ,  'wpse_230940_activation' );    
function wpse_230940_activation() {
  //* Add edit_pages capability to contributors
  $contributor = get_role( 'contributor' );
  $contributor->add_cap( 'edit_pages' );
}

//* Add deactivation hook
register_deactivation_hook( __FILE__ , 'wpse_230940_deactivation' );
function wpse_230940_deactivation() {
  //* Remove edit_pages capability from contributors
  $contributor = get_role( 'contributor' );
  $contributor->remove_cap( 'edit_pages' );
}
-1

A plugin to the rescue. It looks like WPFront User Role Editor is what I was looking for. It produces a very granulated menu of what each role can do. This looks promising.

enter image description here

  • 3
    Nice, next time you do a search before asking here I hope?! Coming up with a plugin as answer seems pretty fishy to me. – Charles Jun 28 '16 at 23:53
  • Yes, I did find this almost after I posted. There is no ill intent. It's a maintained plugin. I feel it's best for the community for two reasons. One, someone smarter may come along and provide a better answer. This is my primary hope. Two, someone else may have a similar question. I'd be delighted that I helped the community. – Rick Jun 29 '16 at 19:00
  • 1
    Wrong, for plugins ppl can look themselves in the plugin repositories. To find help for (own) code/development issues this forum exist. Read, WordPress Stack Exchange is for theme and plugin development. Just a hint Richard, take a visit next time on IRC at #wordpress channel, lots of devs which will help(Live help) you out.(if possible ofcourse) – Charles Jun 30 '16 at 0:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.