WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Possible to make user Capability to Edit Pages, but not to create new pages? (32 posts)

  1. sharris203
    Member
    Posted 4 years ago #

    Hi guys, I know of various plugins to create roles and capabilities, but is it possible to make a user with capability to Edit Pages, but not to create new pages?

  2. Shane G.
    Member
    Posted 4 years ago #

    Hi,

    Check with this plugin:

    http://wordpress.org/extend/plugins/role-scoper/

    Thanks,

    Shane G.

  3. sharris203
    Member
    Posted 4 years ago #

    Here's all of what I'm trying to do: The only options I want users to have is to be able to upload and delete files, and to be able to edit existing pages. A very limited account.

    Role Scoper does have tons of options, but I can't figure out how to remove/hide the link to Add New pages. If I had some CSS code to hide all submenus I think that may work.

    Also, how can I allow them to not just upload files, but also to delete files? It seems all the plugins I try allow them to upload but not delete.

  4. Mark / t31os
    Moderator
    Posted 4 years ago #

    If you're unable to get the functionality you would like (or require) from the plugins available, then you're left with pretty much two options.

    1. Modify/hack the code to do what you want.
    2. Employ a developer to write the customisation for you.

    Alternative role management plugin:
    http://wordpress.org/extend/plugins/members/

  5. kevinB
    Member
    Posted 4 years ago #

    If you decide to use Role Scoper, start with a user whose WP role is Subscriber, Contributor or Author. Then assign (Roles > Pages) that user a Page Editor role for desired page(s). They will not be able to create new pages unless you also also give them a General Role (Roles > General) of Page Author.

  6. sharris203
    Member
    Posted 4 years ago #

    Worked great! Thanks kevinB

    Know how to hide the Tools menu on the left?

  7. Mark / t31os
    Moderator
    Posted 4 years ago #

    Remove the tools menu.

    function remove_tools_menu() {
    	global $menu;
    	unset( $menu[75] );
    }
    add_action( 'admin_menu' , 'remove_tools_menu' );
  8. sharris203
    Member
    Posted 4 years ago #

    Great! Thanks t31os_! Hmm, just a couple more things...

    Any plugin to hide the user's Profile (but not the entire admin area)? And in the header, change Howdy to Hello, and remove Turbo?

  9. sharris203
    Member
    Posted 4 years ago #

    Solved!

    Used WP Hide Dashboard to hide the tools menu, plus various other plugins.

  10. Mark / t31os
    Moderator
    Posted 4 years ago #

    I was beginning to think this was plugin ground, glad you were able to find something to suit your needs.. :)

  11. sharris203
    Member
    Posted 4 years ago #

    1 more thing: How can i hide/unset a submenu item? I'm using WP Hide Dashboard so all i need is the unset function. I want to remove the submenu item: $submenu['edit-pages.php'][10]...

    $menu[20] = array( __('Pages'), 'edit_pages', 'edit-pages.php', '', 'menu-top', 'menu-pages', 'div' );
    	$submenu['edit-pages.php'][5] = array( __('Edit'), 'edit_pages', 'edit-pages.php' );
    	/* translators: add new page */
    	$submenu['edit-pages.php'][10] = array( _x('Add New', 'page'), 'edit_pages', 'page-new.php' );

    The Add New Page submenu does not function for subscribes but they can still see it and I want to remove it from the menu.

    I have tried this but it didn't work:
    unset($submenu['edit-pages.php'][10]);

  12. Mark / t31os
    Moderator
    Posted 4 years ago #

    Assuming you're following the previous example, global the $submenu variable, then unset..

    global $submenu;
    unset( $submenu['edit-pages.php'][10] );

    As i did in the example with the $menu variable..

  13. sharris203
    Member
    Posted 4 years ago #

    Thanks. Well, one more small customization that shouldn't be too hard. I want to use CSS to hide "Add New" buttons on the admin pages.

    This specifically
    <a href="page-new.php" class="button add-new-h2"><?php echo esc_html_x('Add New', 'page'); ?></a>
    and for the code I tried
    button add-new-h2 { visibility:hidden; } in wp-admin.css
    but it didn't work. Any thoughts?

  14. Mark / t31os
    Moderator
    Posted 4 years ago #

    Classes are denoted by a period(dot/fullstop) in CSS, and mutliple classes on the same element do not have a space(well not in the CSS at least)..

    Try the following..

    .button.add-new-h2 {
    	visibility:hidden;
    	display:none;
    }
  15. sharris203
    Member
    Posted 4 years ago #

    Tried that but it didnt work. Found this: http://www.maxdesign.com.au/articles/multiple-classes/ so your code should be correct. Maybe there's a different CSS file I need to use. None of these work

    .button.add-new-h2 {
    	visibility:hidden;
    	display:none;
    }
    .button add-new-h2 {
    	visibility:hidden;
    	display:none;
    }
    button.add-new-h2 {
    	visibility:hidden;
    	display:none;
    }
    .add-new-h2 {
    	visibility:hidden;
    	display:none;
    }
    a.button.add-new-h2 {
    	visibility:hidden;
    	display:none;
    }
    a.button add-new-h2 {
    	visibility:hidden;
    	display:none;
    }
    a.button:add-new-h2 {
    	visibility:hidden;
    	display:none;
    }
    a.add-new-h2 {
    	visibility:hidden;
    	display:none;
    }
  16. Mark / t31os
    Moderator
    Posted 4 years ago #

    Try the CSS definitions with !important..

    eg.

    .button.add-new-h2 {
    	visibility:hidden!important;
    	display:none!important;
    }

    Is there a particular reason you can't just unset this one, like with the others?

  17. sharris203
    Member
    Posted 4 years ago #

    !important didn't work either. I wasn't aware I could use unset for this.
    unset( .button.add-new-h2 ); didn't work

    (Honestly, I just removed the actual button code in the core file. But I like doing things the long, tricky way. Also, I don't want to do it every time I update WordPress.)

  18. Mark / t31os
    Moderator
    Posted 4 years ago #

    unset( .button.add-new-h2 );

    You can't unset CSS classes, unset is for PHP ... it won't work on CSS ..

    What i was saying was, why can you not unset this menu item using the same method we used further up the topic.

    Also, I don't want to do it every time I update WordPress.

    See my example here again.
    http://wordpress.org/support/topic/370002?replies=17#post-1419254

    It wouldn't require that you touch any core files (it's a function, which could be placed in a plugin or theme functions file), so there's no problem with upgrading..

  19. sharris203
    Member
    Posted 4 years ago #

    Ok, I see what you're saying. I don't think this is a menu item. It's the "Add New" button above "All | Published | Trash" on edit-pages.php. It doesn't appear to be a function, just a standard html link with a button image.

  20. sharris203
    Member
    Posted 4 years ago #

    well, lol, unless I can unset this function <?php echo esc_html_x('Add New', 'page'); ?>

  21. Mark / t31os
    Moderator
    Posted 4 years ago #

    Where are you reading that code from?

  22. sharris203
    Member
    Posted 4 years ago #

    edit-pages.php, line 144
    <a href="page-new.php" class="button add-new-h2"><?php echo esc_html_x('Add New', 'page'); ?></a>

  23. Mark / t31os
    Moderator
    Posted 4 years ago #

    Why are you editting core files though?
    Are you wanting to hide this stuff from admins to? (ie. remove it for any users, admin or not)

    If you're hiding this for particular users, you could look at doing it with some form of role management, you don't need to be making changes to core files, that you would essentially lose after any upgrade(unless you keep track of all changes and re-apply them after each upgrade), you should instead remove the necessary capabilities from the given role.

    If you take away the ability for a set role to do a given task, such as adding/editing pages, those items will automatically be hidden from any user with that role, menu items etc... (easy example would be to login to your site as a subscriber, you'll immediately notice various areas missing).

    Right now you're not removing any capability, you're simply hiding the links, meaning that any savy user that realises would still be able to add/edit pages with the right URL query string in the admin area(if the role has the capability required).

    If you want to clarify on why it is you're hiding these perhaps i can offer further advice, but right now i'm a little worried you're hiding these links in expectation that users won't be able to do certain tasks when the links are removed, which wouldn't really be the case(if their role has that capability).

    NOTE: edit-pages.php won't be used as of WP 3.0, just a pre-3.0 warning since you're making changes to it.

  24. sharris203
    Member
    Posted 4 years ago #

    I have the capabilities set correctly. The button/link I'm removing actually does not work for the subscriber role, yet is still visible. If they click it, it doesn't work, says access denied/no permission/etc. Since they can't use it, I don't even want them to see it or be curious about it.

    For my purposes, it doesn't matter if it's not visible to the admin b/c:
    1. The side submenu link is still available for the admin.
    2. I can also type in the url manually to reach the page.

    In WP 3.0, I may have to edit those core files too. If that's not feasible, well I'll just have to let this final customization slide then. Any ETA on WP 3.0? weeks? months?

  25. Mark / t31os
    Moderator
    Posted 4 years ago #

    You could do it with jQuery, or the CSS should work .. it depends if you have your CSS read before or after the admin CSS is loaded by WordPress.

    Just seems a little drastic to be going in there removing a link when CSS should be fine(being a non-JS solution)..

    Are you doing this inside a plugin or theme functions file? (anything you're not changing in core files)..

    I can help you make a basic function for adding CSS to the admin if you like.. we should be able to target the edit-pages.php page specifically to(so the additional CSS isn't loaded on every admin page).

    RE: 3.0, personally i don't know if there's a particular set date, the difference mentioned before was just an observation, and i imagine the change is related to the custom post type support we should hopefully see in 3.0.

  26. sharris203
    Member
    Posted 4 years ago #

    I'm placing the CSS code into /wp-admin/wp-admin.css. I don't know if that is the right file, or if it loads before or after the page loads. I asked about WP 3.0 because if it's coming soon then I'd wait for it instead of trying all this on WP 2.9.

    If you had a function that targets edit-pages.php that would be great! I'm not familiar with writing plugins, but if that would make it upgrade-proof then that'd be best.

  27. Mark / t31os
    Moderator
    Posted 4 years ago #

    Yes, pretty much any page in the admin can be targeted...

    Let me go test some code(under 2.9) and i'll report back, so i don't post something that doesn't work..

  28. Mark / t31os
    Moderator
    Posted 4 years ago #

    This works..

    add_action('admin_init','my_init_method');
    function my_init_method() {
    	// Hook onto print styles action for edit-pages page only
    	add_action('admin_print_styles-edit-pages.php','add_edit_pages_css');
    }
    function add_edit_pages_css() {
    	?>
    	<style type="text/css">
    	.button.add-new-h2 {display:none!important}
    	</style>
    	<?php
    }

    There's another method to do the same, to ensure it loads your CSS after the WordPress stylesheets, using wp_enqueue_style, but that would mean loading an external CSS file just for a single line of code (not really worth it is - i did do it that way before changing my mind and posting the above instead).

    Both approaches work the same, but the above is smaller and easier to understand, and won't require any external files, just move that code into a plugin or a theme's functions.php(how i tested it).

  29. sharris203
    Member
    Posted 4 years ago #

    Sweet! Your code works great. Thanks a lot t31os_!!!

    One last thing... Any way to set the height of the text box when editing a page? The box where you can drag the bottom-right corner. I want to expand it to about twice the size and have that as the default.

  30. Mark / t31os
    Moderator
    Posted 4 years ago #

    Yeah i use to do that myself..

    This works without the init .. (not sure the last one needed it either) ..

    add_action('admin_print_styles-page.php','increase_textarea_css');
    add_action('admin_print_styles-page-new.php','increase_textarea_css');
    add_action('admin_print_styles-post.php','increase_textarea_css');
    add_action('admin_print_styles-post-new.php','increase_textarea_css');
    
    function increase_textarea_css() {
    	?>
    	<style type="text/css">
    	textarea#content {height:600px!important}
    	</style>
    	<?php
    }

    There's 4 cases to catch, but we can just reference the same function since we're using the same CSS for each case. 600px is just an example(you'll notice the difference), adjust as required..

    I'm off to bed shortly(4am here), so hope that helps, i'll check by tomorrow to see how you got on.. ;)

Topic Closed

This topic has been closed to new replies.

About this Topic