ikamal7

add_new_post_status.php

Oct 15th, 2020 (edited)
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.54 KB | None | 0 0
  1. <?php
  2.  
  3. // Registering custom post status
  4. function dom_custom_post_status() {
  5.     register_post_status( 'block', array(
  6.         'label'                     => _x( 'Blocked', 'post' ),
  7.         'public'                    => false,
  8.         'exclude_from_search'       => false,
  9.         'show_in_admin_all_list'    => true,
  10.         'show_in_admin_status_list' => true,
  11.         'show_in_metabox_dropdown'  => true,
  12.         'show_in_inline_dropdown'   => true,
  13.         'date_floating'   => true,
  14.         'post_type'                 => array( 'w2dc_listing' ),
  15.         'label_count'               => _n_noop( 'Blocked <span class="count">(%s)</span>', 'Blocked <span class="count">(%s)</span>' ),
  16.     ) );
  17. }
  18. add_action( 'init', 'dom_custom_post_status' );
  19.  
  20. // Using jQuery to add it to post status dropdown
  21. add_action( 'admin_print_footer_scripts', 'dom_append_post_status_list' );
  22. // add_action( 'admin_print_scripts-post-new.php', 'dom_append_post_status_list' );
  23. function dom_append_post_status_list() {
  24.     global $post;
  25.     $complete = '';
  26.     $label    = '';
  27.     if ( $post->post_type == 'w2dc_listing' ) {
  28.         if ( $post->post_status == 'block' ) {
  29.             $complete = ' selected="selected"';
  30.             $label    = '<span id="post-status-display"> Blocked</span>';
  31.         }
  32.         echo '
  33. <script>
  34.    jQuery(document).ready(function($){
  35.        $("select#post_status").append("<option value=\"block\" ' . $complete . '>Blocked</option>");
  36.        $(".misc-pub-section label").append("' . $label . '");
  37.    });
  38. </script>';
  39.     }
  40. }
Add Comment
Please, Sign In to add comment