1

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

3

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;
}
0

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.

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.