WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 4 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:
PR Number:

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)

screen.php.patch (640 bytes) - added by tychay 5 years ago.
patch to screen.php (on 4.1.1)

Download all attachments as: .zip

Change History (11)

@tychay
5 years ago

patch to screen.php (on 4.1.1)

#2 follow-up: @sc0ttkclark
5 years ago

Patch looks a little odd, but I like the intention.

#3 follow-up: @SergeyBiryukov
5 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 @tychay
4 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 @tychay
4 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' );

#6 @SergeyBiryukov
4 years ago

  • Milestone changed from Awaiting Review to 4.3

#7 @obenland
4 years ago

  • Owner set to SergeyBiryukov
  • Status changed from new to assigned

#8 @obenland
4 years ago

  • Milestone changed from 4.3 to Future Release

#9 @MikeHansenMe
4 years ago

  • Keywords close added

This was added in a similar ticket #32499.

#10 @SergeyBiryukov
4 years ago

  • Keywords close removed
  • Milestone Future Release deleted
  • Resolution set to duplicate
  • Status changed from assigned to closed

Duplicate of #32499.

Note: See TracTickets for help on using tickets.