Update: Create custom post status messages in admin

Adding this snippet to the functions.php of your wordpress theme will let you create custom post status messages.


This is an updated version of the (Create custom post status messages in admin) adding some additional features. Only users with the “publish_posts” capability can change the status while everyone sees what the status (if set) is. 1. Restricting add status with the capability publish_posts 2. Remove status notification selecting none.

 

add_filter( 'display_post_states', 'custom_post_state' );
function custom_post_state( $states ) {
global $post;
$show_custom_state = get_post_meta( $post->ID, '_status' );
// We are using "None" as a way to disable this feature for the current post.
if ( $show_custom_state && $show_custom_state[0] != 'None' ) $states[] = '<span class="custom_state ' . strtolower( $show_custom_state[0] ) . '">' . $show_custom_state[0] . '</span>';
return $states;
}
add_action( 'admin_head', 'status_css' );
function status_css()
{
echo '
<!-- Styling of Custom Statuses -->
<style type="text/css">
.custom{border-top:solid 1px #e5e5e5;}
.custom_state{
font-size:9px;
color:#666;
background:#e5e5e5;
padding:3px 6px 3px 6px;
-moz-border-radius:3px;
-webkit-border-radius:3px;
border-radius:3px;
border-radius:3px;
}
.spelling{background:#4BC8EB;color:#fff;}
.review{background:#CB4BEB;color:#fff;}
.errors{background:#FF0000;color:#fff;}
.source{background:#D7E01F;color:#333;}
.rejected{background:#000000;color:#fff;}
.final{background:#DE9414;color:#333;}
</style>';
}
// Only those with the capability should be able to change things.
if ( current_user_can( 'publish_posts' ) ) {
// Insert our "Custom Status" into the Post Publish Box
add_action( 'post_submitbox_misc_actions', 'custom_status_metabox' );
function custom_status_metabox() {
global $post;
$custom = get_post_custom( $post->ID );
$status = $custom["_status"][0];
$i = 0;
// Available Statuses
$custom_status = array( 'None', 'Spelling', 'Review', 'Errors', 'Source', 'Rejected', 'Final' );
echo '
<div class="misc-pub-section custom">Custom status:
<select name="ourstatus">';
for ( $i = 0; $i < count( $custom_status ); $i++ ) {
echo '<option value="' . $custom_status[$i] . '"';
if ( $status == $custom_status[$i] ) echo ' selected="selected"';
echo '>' . $custom_status[$i] . '</option>';
}
echo '</select></div>';
}
// Save
add_action( 'save_post', 'save_status' );
function save_status( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id;
update_post_meta( $post_id, "_status", $_POST["ourstatus"] );
}
}

Be Sociable, Share!

Leave a comment