admin管理员组

文章数量:1287656

Currently i m using this shorocdes

add_filter( 'post_row_actions', 'remove_row_actions', 10, 1 );
function remove_row_actions( $actions )
{
if( get_post_type() === 'post' ) 
    unset( $actions['edit'] );
return $actions;
}

for removing edit link from published post but this code is applied on all post states and i want to apply this filter only for published and pending post. can any one help me to apply this filter only for published and pending post instead of All posts

Currently i m using this shorocdes

add_filter( 'post_row_actions', 'remove_row_actions', 10, 1 );
function remove_row_actions( $actions )
{
if( get_post_type() === 'post' ) 
    unset( $actions['edit'] );
return $actions;
}

for removing edit link from published post but this code is applied on all post states and i want to apply this filter only for published and pending post. can any one help me to apply this filter only for published and pending post instead of All posts

Share Improve this question edited Sep 15, 2021 at 17:32 techno tech asked Sep 15, 2021 at 17:00 techno techtechno tech 286 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Try this, where I changed the function to accept the second parameter which is the current post in the list table:

add_filter( 'post_row_actions', 'remove_row_actions', 10, 2 );
function remove_row_actions( $actions, $post )
{
    if ( $post && 'post' === $post->post_type &&
        in_array( $post->post_status, array( 'publish', 'pending' ) )
    ) {
        unset( $actions['edit'] );
    }

    return $actions;
}

本文标签: functionsremove edit link only for published post and pending post