1

I am using Wordpress 3.3.2 with the following plugin: - http://wordpress.org/extend/plugins/advanced-access-manager/

The plugin works perfectly but the author said there is currently no way to achieve this from the plugin, So I am wondering if there is either another plugin or any code modifications I can make to achieve them.

  1. I created a custom user role Called "Member"
  2. I applied certain permissions so the user can only sees options to make posts in the backend.
  3. When making a post, the user does not see the "Edit" option to change the permalink.

  4. The problem comes after the user submits the Post. Right below the post title field it shows the permalink and shows an "Edit" button which allows the user to change the permalink.

Is there any way to remove either the "Edit" button so they can't edit the permalink, or removing that entire line altogether so the permalink doesn't show for them at all?

Thank you in advance!

3 Answers 3

3

You could do something like (in your functions.php file);

if(current_user_can('member')){  

add_filter('get_sample_permalink_html', 'perm', '',4);

function perm($return, $id, $new_title, $new_slug){
    
    $post = get_post( $id );

    if( ! $post || ( $post->post_type !== 'testimonials' ) )
    {
        return $return;
    }

    return preg_replace(
        '/<span id="edit-slug-buttons">.*<\/span>|<span id=\'view-post-btn\'>.*<\/span>/i', 
        '', 
        $return
    );
}

To give credit where credit is due, everything between

if( $_GET['role'] == "member" ) {

and

}

...is directly taken from this Question & Answer HERE courtesy of Jonathan Wold

UPDATE

The conditional if statement of;

if( $_GET['role'] == "member" ) {//code here }

was replaced with,

if(current_user_can('member')){ //code here}

...in this instance.

13
  • Thank you for the reply and link! Would I edit the functions.php file from my theme, or from the wp-includes folder? I want to make sure if I upgrade WP, the change isn't lost... but if there is no way around that then no biggie :)
    – Damainman
    Commented Apr 22, 2012 at 9:16
  • I tried putting that in both locations, with no success in either.
    – Damainman
    Commented Apr 22, 2012 at 10:04
  • You should never edit the WP core files. Only edit files contained within your Themes/your-theme folder. Change testimonial to match your post type. If its just the regular post then type post. This code should go into your functions.php file within your theme folder.
    – Adam
    Commented Apr 22, 2012 at 12:28
  • Thanks for the reply and clarification on where to place the code. I've tried adding the code to both functions.php files(not at the same time of course).. I even changed the user to administrator and tried other post types. Tried capitalizing first letter of the member role as well. Tried putting it at the top and at the bottom of the functions.php page. I've spent about 4-5 hours googling hooks and functions and forums, but I still can not seem to get this to work.
    – Damainman
    Commented Apr 22, 2012 at 15:07
  • Nm, the code works... just not with the IF statement. I am going to see what I can find.
    – Damainman
    Commented Apr 22, 2012 at 15:34
0

Just to provide an additional to accomplish this, the following code worked for me as well but it didn't make use of the IF statement for the user role. This would be added to the functions.php file. I found the information at: https://gist.github.com/1967124

 <?php

add_action('admin_head', 'hide_edit_permalinks_admin_css');

function hide_edit_permalinks_admin_css()
{
    ?>
<style type="text/css">
<!--
#titlediv
{
margin-bottom: 10px;
}
#edit-slug-box
{
display: none;
}
-->
</style>
<?php
}
2
0
// get the role object
$role = get_role( 'editor' );

// remove cap
$role->remove_cap( 'edit_post' );

Not sure but this should work, isn't it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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