I got your hook up ?? Maybe someone can polish it up! You will need to add the capability, assign_pitch_posts.
in the functions.php file add
/* Add custom actions in the posts view
*
*/
function add_claim_to_pitch_posts_rows($actions, $post_id) {
$post = get_post($post_id);
if ( $post->post_status == "pitch" && current_user_can( 'assign_pitch_posts' ) ) {
unset( $actions['view'] );
$actions['assign'] = '<a href="https://domain.com/wp-admin/assign.php?post='.$post->ID.'&action=assign" title="' . esc_attr( __( 'Claim this pitch' ) ) . '">' . __( 'Claim' ) . '</a>';
}
return $actions;
}
add_filter('post_row_actions','add_claim_to_pitch_posts_rows');
function add_unassign_to_posts_rows($actions, $post_id) {
$post = get_post($post_id);
if ( $post->post_status == "assigned" && current_user_can( 'assign_pitch_posts' ) && current_user_can( 'edit_post', $post->ID ) ) {
$actions['assign'] = '<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 = "https://domain.com/wp-admin/assign.php?post='.$post->ID.'&action=unassign";'.
'}}</script><a href="javascript:void(0)" onclick="unClaim_'.$post->ID.'()" title="' . esc_attr( __( 'Unclaim this post' ) ) . '">' . __( 'Unclaim' ) . '</a>';
}
return $actions;
}
add_filter('post_row_actions','add_unassign_to_posts_rows');
Create a file called assign.php in the wp-admin folder and add this to the file:
<?php
/**
* Assign post to writer.
*
*/
/** WordPress Administration Bootstrap */
require_once('./admin.php');
if ( isset( $_GET['post'] ) )
$post_id = $post_ID = (int) $_GET['post'];
elseif ( isset( $_POST['post_ID'] ) )
$post_id = $post_ID = (int) $_POST['post_ID'];
else
$post_id = $post_ID = 0;
$post = $post_type = $post_type_object = null;
if ( $post_id )
$post = get_post( $post_id );
if ( $post ) {
$post_type = $post->post_type;
$post_type_object = get_post_type_object( $post_type );
}
if ( empty( $post_id ) ) {
wp_redirect( admin_url('post.php') );
exit();
}
$p = $post_id;
if ( empty($post->ID) )
wp_die( __('You attempted to modify an item that doesn’t exist. Perhaps it was deleted?') );
if ( null == $post_type_object )
wp_die( __('Unknown post type.') );
if ( 'trash' == $post->post_status )
wp_die( __('You can’t assign this item because it is in the Trash. Please restore it and try again.') );
switch($_GET['action']) {
case 'assign':
if ( !current_user_can('assign_pitch_posts') )
wp_die( __('You are not allowed to assign this item.') );
if ( $post->post_status == "pitch" ) {
$wpdb->query(
"
UPDATE $wpdb->posts
SET post_status = 'assigned', post_author = " . wp_get_current_user()->ID . "
WHERE ID = $p AND post_status = 'pitch'
");
}
wp_redirect( admin_url('edit.php?post_status=pitch&post_type=post') );
exit();
break;
case 'unassign':
if ( !current_user_can('assign_pitch_posts') )
wp_die( __('You are not allowed to unassign this item.') );
if ( $post->post_status == "assigned" ) {
$wpdb->query(
"
UPDATE $wpdb->posts
SET post_status = 'pitch', post_author = 159
WHERE ID = $p AND post_status = 'assigned'
");
}
wp_redirect( admin_url('post.php') );
exit();
break;
default:
wp_redirect( admin_url('post.php') );
exit();
break;
}
Your welcome!