Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have made a custom post type named as: slider, in my plugin class, I am adding a filter which calls the method remove_row_action that unsets view links from actions

   add_filter('post_row_actions', array(&$this, 'remove_row_actions'), 10, 1);

   public function remove_row_actions($action) {

    if (isset($_GET['post_type'])  && $_GET['post_type'] == 'slider')) {
        unset($action['view']);
        return $action;
    }else{
        return $action;
    }
}

It works perfectly well, but I believe there must be a cleaner way in which the add_filter only applies for the custom post type, instead of me checking it by the GET variable

share|improve this question

2 Answers 2

Yes, you're right. There is a clever way. post_row_actions filter can accept also second param $post from which you can get it's post_type. See the code:

add_filter( 'post_row_actions', array( $this, 'remove_row_actions' ), 10, 2);
public function remove_row_actions( $action, $post ) {
    if ( 'slider' === get_post_type( $post ) ) {
        unset $action['view'];
        return $action;
    }
    return $action;
}
share|improve this answer

Just inspect the get_current_screen() object. It will tell you what you got. The same goes for the $query argument that you can find inside the parse_request and pre_get_posts filters.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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