Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

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.

share|improve this question
    
This is a per user option and saved into the user meta via ajax. Maybe you want to alter your question based on this information. –  kaiser Jun 28 '12 at 12:04
    
Hey @Michael Ecklund, did my answer not address your question? –  MikeSchinkel Jul 2 '12 at 3:09

1 Answer 1

up vote 6 down vote accepted

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?

share|improve this answer
1  
Awww, you’re back! :) –  toscho Jun 29 '12 at 6:48
1  
@toscho Thanks for noticing. I've been less than healthy and clients have been demanding, so back only a bit. –  MikeSchinkel Jun 29 '12 at 16:20
    
@MikeSchinkel How would I go about removing let's say, "wpseo-score" from the post type of let's say, "business"? –  Michael Ecklund Jul 3 '12 at 0:31
1  
@MichaelEcklund What is 'wpseo-score'?; are you using a plugin or theme that adds it, like maybe WordPress SEO by Yoast? Do any of these links help? gist.github.com/2927217 gist.github.com/2997070 wordpress.org/support/topic/… –  MikeSchinkel Jul 3 '12 at 5:13
    
@MikeSchinkel Wow thanks. all I simply had to do was add_filter('wpseo_use_page_analysis', '__return_false'); ... and all of those cluttered columns are gone now. But let's say a plugin wasn't so graceful in providing hooks for it's users? Could you please update you answer geared for removing a custom column name from a custom post type? I can assure you I am not the only one in this community that could benefit from it. Aside from that, thanks for the detailed answer. –  Michael Ecklund Jul 3 '12 at 20:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.