Skip to content

Instantly share code, notes, and snippets.

@antoniofrignani
Created June 4, 2012 09:40
Show Gist options
  • Save antoniofrignani/2867487 to your computer and use it in GitHub Desktop.
Save antoniofrignani/2867487 to your computer and use it in GitHub Desktop.
[WP] - Update: Create custom post status messages in admin
// http://wpsnipp.com/index.php/functions-php/update-create-custom-post-status-mesasges-in-admin/
// for layout fixes: http://pastebin.com/zNHEZMKR
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"] );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment