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.
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.
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.
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 forpost_type='post'
andpost_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 inMichael_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?