0

I thought I could use the filter the_title. But that let's you change the text only. I would like to disable the title link for specific pages. So the title text would stay the same, but the user wouldn't be able to click on it and get to the edit post page. I can think of two ways of doing this.

  1. Adding a class to disable the link via css.
  2. Disabling or removing the link vis JS.

Before going either route, I wanted to know if there's a filter that will accomplish that without having to resort to JS or css?

I have been searching the codex and hookr.io for filters , but I cannot find anything.

1

I would try something like below. Since current_user_can is called right before displaying the link, we have to hook where capabilities are checked.

function wpse200630_has_cap_check( $allcaps, $caps, $args, $user ){
     if( function_exists( 'get_current_screen' ) ){
        $screen = get_current_screen();
        if( $screen->base == 'edit'  && $screen->post_type == 'my_post_type'){
            if ( 'edit_post' == $args[0] || 'delete_post' == $args[0] ) {
                if( !empty( $args[2] ) && $args[2] == ID_TO_DISABLE )
                    return array();
            }
        }
    }
    return $allcaps ;
} 
add_filter( 'user_has_cap', 'wpse200630_has_cap_check', 10, 3 );
  • Thanks for the info. I will have to test it out, but it seems that this could work. – gdaniel Sep 4 '15 at 14:04
  • This answer was very useful, thanks. It will help me also do other things related to permissions. I wish there was a nice hooks/filter guide. Most sites list them, but don't explain how they work. – gdaniel Sep 4 '15 at 18:52

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.