Created
November 3, 2018 07:29
-
-
Save ruman/d40000e9c74737c567738dc2d591bff1 to your computer and use it in GitHub Desktop.
Custom Post Status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Registering custom post status | |
function wpb_custom_post_status(){ | |
register_post_status('inactive', array( | |
'label' => _x( | |
'Inactive', 'post' ), | |
'public' => false, | |
'exclude_from_search' => false, | |
'show_in_admin_all_list' => true, | |
'show_in_admin_status_list' => true, | |
'label_count' => _n_noop( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>' ), | |
) ); | |
} | |
add_action( 'init', 'wpb_custom_post_status' ); | |
// Using jQuery to add it to post status dropdown | |
add_action('admin_footer-post.php', 'wpb_append_post_status_list'); | |
function wpb_append_post_status_list(){ | |
global $post; | |
$complete = ''; | |
$label = ''; | |
if($post->post_type == 'post'){ | |
if($post->post_status == 'inactive'){ | |
$complete = ' selected="selected"'; | |
$label = '<span id="post-status-display"> Inactive</span>'; | |
} | |
echo ' | |
<script> | |
jQuery(document).ready(function($){ | |
$("select#post_status").append("<option value=\"inactive\" '.$complete.'>Inactive</option>"); | |
$(".misc-pub-section label").append("'.$label.'"); | |
}); | |
</script> | |
'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment