Opened 10 years ago
Closed 9 years ago
#31989 closed enhancement (duplicate)
Allow developer to default hide columns
Reported by: | tychay | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.1 |
Component: | Options, Meta APIs | Keywords: | |
Focuses: | administration | Cc: |
Description
Currently, the only way to hide columns by default is to write everyone's user_meta with the array for the hidden columns on a particular screen. However, that isn't the case with metaboxes since WordPress 3.1.
Instead of cluttering up the database, add a default hook for columns the same way as it's done for meta_boxes.
I'm including a patch to wp-admin/incluides/screen.php with the relevant code to make things easy. ;-)
Attachments (1)
Change History (11)
#3
follow-up:
↓ 5
@
10 years ago
Currently, the only way to hide columns by default is to write everyone's user_meta with the array for the hidden columns on a particular screen.
You can use get_user_option filter without actually writing user meta:
function wp31989_set_hidden_columns_for_posts_screen( $result ) { if ( ! $result ) { $result = array( 'author', 'categories' ); } return $result; } add_filter( 'get_user_option_manageedit-postcolumnshidden', 'wp31989_set_hidden_columns_for_posts_screen' );
#4
in reply to:
↑ 2
@
9 years ago
Replying to sc0ttkclark:
Patch looks a little odd, but I like the intention.
I basically pirated the code from the way metabox handles it (in the same file). In fact, my patch accidentally left in the "hide slug boxes by default" comment :-D
#5
in reply to:
↑ 3
@
9 years ago
Replying to SergeyBiryukov:
That's a great idea, but it gets pretty hairy in non-obvious ways. The way the code is written it depends on an artifact where screen_options() writes an array of a single element (empty string) when all the column boxes are unchecked. It'd probably be better to hard check for it. Also, it takes a while to get a handle of which hook to look for get_user_option_manage<screen_id>columnshidden
. That's pretty opaque to most people.
Besides, my patch is the same code and filter system as used for default metaboxes hide/show.
function wp31989_set_hidden_columns_for_posts_screen( $result ) { if ( $result === false ) { $result = array( 'author', 'categories' ); } return $result; } add_filter( 'get_user_option_manageedit-postcolumnshidden', 'wp31989_set_hidden_columns_for_posts_screen' );
patch to screen.php (on 4.1.1)