I made the following changes to make the “Claim” a button in its own column on the posts admin page and change the admin url to admin_url(). I’m using the custom status “available story” and giving everyone with “write_posts” capability the option to claim a post. Also, I added “Already Claimed” when a post is claimed.
/*
* Add custom claim column in the posts view
*/
function remove_row_actions( $actions )
{
if( get_post_type() === 'post' )
unset( $actions['view'] );
return $actions;
}
function add_claim_column_modify_post_table( $column ) {
$column['claim'] = 'Claim';
return $column;
}
add_filter( 'manage_posts_columns', 'add_claim_column_modify_post_table' );
function add_claim_button_modify_post_table_row( $column_name, $post_id ) {
$post = get_post($post_id);
switch ($column_name) {
case 'claim':
if ( $post->post_status == "available-story" && current_user_can( 'write_posts' ) ) {
add_filter( 'post_row_actions', 'remove_row_actions', 10, 1 );
echo '<a href="' . admin_url('assign.php?post='.$post_id.'&action=assign') . '" class="button-secondary" title="' . esc_attr( __( 'Claim this Article' ) ) . '">' . __( 'Claim' ) . '</a>';
}
if ( ($post->post_status == "assigned" || $post->post_status == "in-progress" )&& current_user_can( 'edit_post', $post_id ) ) {
echo '<script>function unClaim_'.$post_id.'()'.
'{ var r = confirm("Are you sure you want to unclaim this post?\n You will lose all work done on the article.");'.
'if (r==true){ window.location.href = "' . admin_url('assign.php?post='.$post_id.'&action=unassign') . '";
}}</script><a href="javascript:void(0)" onclick="unClaim_'.$post_id.'()" class="button-secondary" title="' . esc_attr( __( 'Unclaim this Article' ) ) . '">' . __( 'Unclaim' ) . '</a>';
}
if ( $post->post_status == "assigned" && !current_user_can( 'edit_post', $post_id ) ) {
echo 'Already Claimed';
}
break;
default:
}
}
add_filter( 'manage_posts_custom_column', 'add_claim_button_modify_post_table_row', 10, 2 );