Custom Post Row Actions

Question

I came across this question while writing this question. I have one question that extends upon that question.

I figured out that you use the get_delete_post_link filter to create a new url for my actions (or a similar function — In any case, I’m using that one with the boolean at the end). Only thing is, I don’t know how to capture the event now. Some help would be appreciated considering I can’t find many examples of post row actions on Google. :-/

public function _wp_filter_get_delete_post_link( $post_id, $deprecated, $force_delete = false )
{
    if ( ! empty( $deprecated ) )
    {
        _deprecated_argument( __FUNCTION__, '3.0.0' );
    }

    $post = &get_post( $post_id );      
    if ( ! $post ) return;

    if ( strcmp($post->post_type, "visitor") ) return;

    $post_type_object = get_post_type_object( $post->post_type );
    if ( !$post_type_object ) return;
    if ( !current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) return;
    // http://localhost/wordpress/wp-admin/post.php?post=163&action=trash&_wpnonce=a56abdcbb3

    $action = ( $force_delete ? 'logout' : 'login' );

    $delete_link = add_query_arg( 'action', $action, admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) );

    return wp_nonce_url( $delete_link, "$action-{$post->post_type}_{$post->ID}" );
}

And, if you’re needing some more information on how I’m using it, here’s some more code:

public function _wp_post_row_actions( $actions, $post )
{
    if ( $post->post_type == 'visitor' )
    {
        //unset( $actions['edit'] );
        unset( $actions['inline hide-if-no-js'] );
        unset( $actions['trash'] );
        unset( $actions['view'] );

        $state = get_post_meta( $post->ID, 'v_state', true ) === 'in';

        if ( $state )
        {
            $actions['trash'] = get_delete_post_link( $post->ID, '', true );    // Logout
            // get_delete_post_link
        }
        else
        {
            $actions['trash'] = get_delete_post_link( $post->ID );  // Login
        }
    }

    return $actions;
}

EDIT: Well, the above isn’t complete. I just noticed that it doesn’t actually generate a link which is weird. So, I guess what I’m asking is for a way to customize the Post Row Actions for my custom post type by adding a “Logout/Login” link in place of the $actions['trash'] link.

0
zack 3 months 0 Answers 20 views 0

Leave an answer