daily pastebin goal
65%
SHARE
TWEET

Untitled

a guest Jul 27th, 2011 154 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_filter( 'display_post_states', 'custom_post_state' );
  2. function custom_post_state( $states ) {
  3.         global $post;
  4.         $show_custom_state = get_post_meta( $post->ID, '_status' );
  5.         // We are using "None" as a way to disable this feature for the current post.
  6.         if ( $show_custom_state && $show_custom_state[0] != 'None' ) $states[] = $show_custom_state[0];
  7.         return $states;
  8. }
  9. add_action( 'admin_head', 'status_css' );
  10. function status_css()
  11. {
  12.         echo '
  13.         <!-- Styling of Custom Statuses -->
  14.         <style type="text/css">
  15.                 .custom{border-top:solid 1px #e5e5e5;}
  16.                 .custom_state{
  17.                         font-size:9px;
  18.                         color:#666;
  19.                         background:#e5e5e5;
  20.                         padding:3px 6px 3px 6px;
  21.                         -moz-border-radius:3px;
  22.                        -webkit-border-radius:3px;
  23.                        border-radius:3px;
  24.                         border-radius:3px;
  25.                 }
  26.                 .spelling{background:#4BC8EB;color:#fff;}
  27.                 .review{background:#CB4BEB;color:#fff;}
  28.                 .errors{background:#FF0000;color:#fff;}
  29.                 .source{background:#D7E01F;color:#333;}
  30.                 .rejected{background:#000000;color:#fff;}
  31.                 .final{background:#DE9414;color:#333;}
  32.         </style>';
  33. }
  34. // Only those with the capability should be able to change things.
  35. if ( current_user_can( 'publish_posts' ) ) {
  36.         // Insert our "Custom Status" into the Post Publish Box
  37.         add_action( 'post_submitbox_misc_actions', 'custom_status_metabox' );
  38.         function custom_status_metabox() {
  39.                 global $post;
  40.                 $custom = get_post_custom( $post->ID );
  41.                 $status = $custom["_status"][0];
  42.                 $i = 0;
  43.                 // Available Statuses
  44.                 $custom_status = array( 'None', 'Spelling', 'Review', 'Errors', 'Source', 'Rejected', 'Final' );
  45.                 echo '
  46.                 <div class="misc-pub-section custom">Custom status:
  47.                 <select name="ourstatus">';
  48.                         for ( $i = 0; $i < count( $custom_status ); $i++ ) {
  49.                                 echo '<option value="' . $custom_status[$i] . '"';
  50.                                 if ( $status == $custom_status[$i] ) echo ' selected="selected"';
  51.                                 echo '>' . $custom_status[$i] . '</option>';
  52.                         }
  53.                 echo '</select></div>';
  54.         }
  55.         // Save
  56.         add_action( 'save_post', 'save_status' );
  57.         function save_status( $post_id ) {
  58.                 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id;
  59.                 update_post_meta( $post_id, "_status", $_POST["ourstatus"] );
  60.         }
  61. }
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. function custom_post_states( $post_states ) {
  69.    foreach ( $post_states as &$state ){
  70.    $state = '<span class="'.strtolower( $state ).' states">' . str_replace( ' ', '-', $state ) . '</span>';
  71.    }
  72.    return $post_states;
  73. }
  74. add_filter( 'display_post_states', 'custom_post_states' );
  75. function custom_post_states_css(){
  76.         echo '<style>
  77.                 .post-state .states{
  78.                         font-size:10px;
  79.                         padding:3px 8px 3px 8px;
  80.                         -moz-border-radius:2px;
  81.                         -webkit-border-radius:2px;
  82.                         border-radius:2px;
  83.                         }
  84.                 .post-state .password{background:#000;color:#fff;}
  85.                 .post-state .pending{background:#83CF21 !important;color:#fff;}
  86.                 .post-state .private{background:#E0A21B;color:#fff;}
  87.                 .post-state .draft{background:#006699;color:#fff;}
  88.               </style>';
  89. }
  90. add_action('admin_head','custom_post_states_css');
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top