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.
The main problem is that $actions accepts the whole anchor tag for the link and get_delete_post_link function outputs just the url.
So if You are just looking to replace the label “Trash” then you can use the post_row_actions filter hook with a simple function
Something like this
This will generate a logout if the meta is “IN” and login if other wise but both links will delete the post. and i would add a check to see if the post is already in the trash.
But its a start and i hope it helps.
You can link to your own function like below. I’m passing a url parameter along with the post id, then I’m seeing if that parameter is set, and calling a function based on that. If you want the logout url instead of the custom url, try replacing the anchor with this…
<a href="<?php echo wp_logout_url( home_url() ); ?>" title="Logout">Logout</a>
. Obviously you’d have to login to see that ‘logout’ link, hence I don’t see a point in putting a login link over there!Let me know if it worked!
Thanks,
Rutwick