Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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[] = $show_custom_state[0];
- 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"] );
- }
- }
- function custom_post_states( $post_states ) {
- foreach ( $post_states as &$state ){
- $state = '<span class="'.strtolower( $state ).' states">' . str_replace( ' ', '-', $state ) . '</span>';
- }
- return $post_states;
- }
- add_filter( 'display_post_states', 'custom_post_states' );
- function custom_post_states_css(){
- echo '<style>
- .post-state .states{
- font-size:10px;
- padding:3px 8px 3px 8px;
- -moz-border-radius:2px;
- -webkit-border-radius:2px;
- border-radius:2px;
- }
- .post-state .password{background:#000;color:#fff;}
- .post-state .pending{background:#83CF21 !important;color:#fff;}
- .post-state .private{background:#E0A21B;color:#fff;}
- .post-state .draft{background:#006699;color:#fff;}
- </style>';
- }
- add_action('admin_head','custom_post_states_css');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement