0

I have created a custom post type, but I want to remove the View link from actions, in the listing of the custom post.

I have tried this snippet

   add_filter( 'post_row_actions',array(&$this, 'remove_row_actions', 10, 1));
   public function remove_row_actions($action){
       unset($action['view']);
       return $action;
   }

But it throws

call_user_func_array() expects parameter 1 to be a valid callback, array must have exactly two members in D:\wamp\www\wordpress\wp-includes\plugin.php on line 173

4 Answers 4

1

You've got typo in your add_filter. Try this:

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

public function remove_row_actions($action){
    unset($action['view']);
    return $action;
}
2
  • doesnt work still, i renamed post_row_actions to page_row_actions also, still it doesnt get removed Commented Mar 14, 2013 at 14:32
  • Must be something with your class code. Inserting this code into functions.php works great: add_filter( 'post_row_actions', 'remove_row_actions', 10, 1); function remove_row_actions($action){ unset($action['view']); return $action; } Commented Mar 14, 2013 at 14:43
1

The difference between class methods and functions is that you don't throw in an array() when calling the function and ommit the leading public/protected/private/static string in front of function. Also don't use the & when calling $this (which is the current class object), as it's PHP4 syntax for passing the class as reference. PHP5 doesn't need this. The third note is, that you use the array() in the way array( __CLASS__, 'method_name' ). The priority 10 and the number of arguments 1 as separate arguments and don't belong inside the array.

   add_filter( 'post_row_actions', 'wpse90843_remove_row_actions' );
   public function wpse90843_remove_row_actions( $action )
   {
       unset $action['view'];
       return $action;
   }

Last note: Don't just grab a snippet from somewhere if you don't understand what you're doing. Get someone who can read this for you. Stuff like this can seriously mess up your installation.

1

None of these answers address that the OP asks how to do this for a custom post type. Unsetting $action['view'] will remove it for all posts, pages and custom post types if you don't get more specific.

Here's what I came up with. (Replace "mycustomtheme" with your theme or plugin slug, replace "myposttype" with your custom post type slug.)

add_filter( 'post_row_actions', 'mycustomtheme_remove_myposttype_row_actions' );
function mycustomtheme_remove_myposttype_row_actions( $action )
{
    if ('myposttype' == get_post_type()) {
        unset($action['view']);
    }
    return $action;
}
0

You will also need to remove the 'public' if it is not in a class.

add_filter( 'post_row_actions', 'wpse90843_remove_row_actions' );
function wpse90843_remove_row_actions( $action )
{
    unset($action['view']);
    return $action;
}

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.