Created
          August 31, 2025 06:16 
        
      - 
      
 - 
        
Save mofizul21/f998b74508b41527f8602f3f3a946003 to your computer and use it in GitHub Desktop.  
    Disable Publish box for demo user
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | <?php | |
| public function __construct() { | |
| add_action( 'add_meta_boxes', [ $this, 'disable_publish_box' ], 99 ); | |
| } | |
| /** | |
| * Disables the publishing meta box and shows a notice in a single method. | |
| * | |
| * @since 1.0.0 | |
| * @return void | |
| */ | |
| public function disable_publish_box(): void { | |
| if ( get_current_screen()->id === self::POST_TYPE ) { | |
| remove_meta_box( 'submitdiv', self::POST_TYPE, 'side' ); | |
| add_meta_box( | |
| 'cpsfwc-disabled-submitdiv', | |
| esc_html__( 'Publish' ), | |
| function() { | |
| ?> | |
| <div class="submitbox" id="submitpost"> | |
| <div id="major-publishing-actions" style="background: #fff;"> | |
| <div class="notice notice-error inline" style="margin: 10px;"> | |
| <p><?php esc_html_e( "This action is disabled for demouser.", 'category-products-slider-for-woocommerce' ); ?></p> | |
| </div> | |
| <div id="publishing-action"> | |
| <span class="spinner"></span> | |
| <input name="original_publish" type="hidden" id="original_publish" value="Update"> | |
| <input name="save" type="submit" class="button button-primary button-large" id="publish" value="Update" disabled="disabled" | |
| style="opacity: 0.5;"> | |
| </div> | |
| <div class="clear"></div> | |
| </div> | |
| </div> | |
| <?php | |
| }, | |
| self::POST_TYPE, | |
| 'side', | |
| 'high' | |
| ); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment