How to Remove Certain Screen Options and Table Columns from post type in wp_list_table?

On the page where we list all posts made: example.domain.com/wp-admin/edit.php

There is a Screen Options tab in the upper right corner. Upon clicking this, a menu slides down. Contained within this slide down menu, are check boxes. When checking or unchecking these check boxes, certain columns in the post table are shown/hidden, depending on whether they are checked or not.

Read More

I am looking for a way to programmatically obtain a list of all of these registered Screen Options for this post type (Default post type: post). Once I obtain a list of these registered screen options, I will check to see if a certain array of options are listed. If they match a listed item, I plan on removing those options.

WordPress - Screen Options - List Posts
Click Here For Full Size Screenshot

Question
How can I programmatically obtain a list of all registered Screen Options on post types (page with table listing each post)?

Looking for a solution similar to the solution provided for removing certain screen options and meta boxes from add/edit post type.

Related posts

Leave a Reply

1 comment

  1. What you need is to modify the $columns variable that is used during list display which you can modify using the 'manage_posts_columns' and 'manage_pages_columns' hooks for post_type='post' and post_type='page', respectively. If you want to ignore custom post types you can inspect the 2nd parameter passed to 'manage_posts_columns' as I did in my example to show how.

    So let’s assume you want to get rid of the “Comments” screen option and it’s associated column which you see in these screenshot for Posts and Pages, respectively:


    Drop the following class into your theme’s functions.php file or in a plugin you might be building and this code will remove the “Comments” screen option and it’s associated column (Since this answer is similar to your other question, I added a "2" to the class name, hence in Michael_Ecklunds_Admin_Customizer2):

    class Michael_Ecklunds_Admin_Customizer2 {
      function __construct() {
        add_action( 'manage_pages_columns', array( $this, 'manage_columns' ) );
        add_action( 'manage_posts_columns', array( $this, 'manage_columns' ), 10, 2 );
      }
      function manage_columns( $columns, $post_type = 'page' ) { //2nd param not passed for pages
        if ( in_array( $post_type, array( 'post', 'page' ) ) ) {
          // This is only for posts and pages, 'if (in_array(...))' just illustrates how.
          unset( $columns['comments'] );
        }
        return $columns;
      }
    }
    new Michael_Ecklunds_Admin_Customizer2();
    

    And here’s what it looks like after you’ve added the above code to a WordPress 3.4 site:


    Using the Zend debugger within PhpStorm here is the inspection of $columns within the 'manage_posts_columns' hook so you can see what values a default installation of WordPress 3.4 has for the Post edit list (I’ve circled the array indexes I referenced in my example, i.e. $columns['comments']:

    Hopefully this is what you were looking for?