WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#9606 closed feature request (fixed)

screen_layout for plugins

Reported by: arena Owned by: arena
Milestone: 2.8 Priority: high
Severity: normal Version: 2.8
Component: Administration Keywords: has-patch tested commit
Focuses: Cc:

Description

In order to allow plugins to integrate this new wp feature !

function screen_layout($screen) {
	global $screen_layout_columns;

	switch ( $screen ) {
		case 'dashboard':
			$screen_layout_columns = get_user_option('screen_layout_dashboard');
			$num = 4;
			break;
		case 'post':
			$screen_layout_columns = get_user_option('screen_layout_post');
			$num = 2;
			break;
		case 'page':
			$screen_layout_columns = get_user_option('screen_layout_page');
			$num = 2;
			break;
		case 'link':
			$screen_layout_columns = get_user_option('screen_layout_link');
			$num = 2;
			break;
		default:
			$screen_layout_columns = 0;
			return '';
	}

// the following test is useless !
	if ( ! $screen_layout_columns )
			$screen_layout_columns = 2;

	$i = 1;

to be replaced by

function screen_layout($screen) {
	global $screen_layout_columns;

	$wp_screen_layouts = array('dashboard' => 4, 'post' => 2, 'page' => 2, 'link' => 2);

	$wp_screen_layouts = apply_filters('screen_layout', $wp_screen_layouts, $screen);

	if (!isset($wp_screen_layouts[$screen])) {
		$screen_layout_columns = 0;
		return '';
	}

	$screen_layout_columns = get_user_option("screen_layout_$screen");
	$num = $wp_screen_layouts[$screen];

	$i = 1;

Attachments (2)

screen_layout.diff (1.4 KB) - added by arena 6 years ago.
9606.diff (1.2 KB) - added by arena 6 years ago.

Download all attachments as: .zip

Change History (17)

@arena6 years ago

comment:1 @arena6 years ago

  • Owner changed from anonymous to arena

comment:2 @arena6 years ago

  • Keywords needs-testing added
  • Priority changed from normal to high

comment:3 @arena6 years ago

  • Version set to 2.8

comment:4 @Denis-de-Bernardy6 years ago

  • Keywords tested added; needs-testing removed

comment:5 @azaozz6 years ago

This heavily depends on js and the actual html of the pages, don't think plugins would be able to use it other than disabling it when the user wants to switch number of columns. Don't think that's needed.

comment:6 follow-up: @Denis-de-Bernardy6 years ago

unless you build an editor for a different data type and write the needed scripts.

comment:7 in reply to: ↑ 6 ; follow-ups: @azaozz6 years ago

Replying to Denis-de-Bernardy:

unless you build an editor for a different data type and write the needed scripts.

In this case the page would be mostly copied from the write posts page? Can probably use the same columns setting too.

Actually the different settings for posts and pages should probably be merged too, don't see a used case where one would need 2 columns and the other only one as both screens are almost identical.

The patch also wouldn't work if the user_option is not set (the "useless" check does exactly that).

comment:8 in reply to: ↑ 7 @Denis-de-Bernardy6 years ago

Replying to azaozz:

Actually the different settings for posts and pages should probably be merged too, don't see a used case where one would need 2 columns and the other only one as both screens are almost identical.

it depends on his prefs. suppose a user sticks to the default layout on posts (which are short), and moves all of the widgets to the right into the middle column on pages, to have a wider editor.

comment:9 in reply to: ↑ 7 ; follow-up: @arena6 years ago

Replying to azaozz:

Replying to Denis-de-Bernardy:

unless you build an editor for a different data type and write the needed scripts.

In this case the page would be mostly copied from the write posts page? Can probably use the same columns setting too.

Actually the different settings for posts and pages should probably be merged too, don't see a used case where one would need 2 columns and the other only one as both screens are almost identical.

The patch also wouldn't work if the user_option is not set (the "useless" check does exactly that).

(the "useless" check does exactly that).

sorry if i follow the code, in the switch, if the $screen is not found => return
so in the test :

if ( ! $screen_layout_columns )

$screen_layout_columns is always true...

comment:10 in reply to: ↑ 9 @azaozz6 years ago

Replying to arena:

$screen_layout_columns is always true...

Unless the $screen is found but the option is not set. Then $screen_layout_columns = false so it needs default value which is 2. See get_user_option()

comment:11 @arena6 years ago

true !

@arena6 years ago

comment:12 @arena6 years ago

  • Keywords needs-testing added; tested removed

Patch fixing the test if get_user_option not found

Some plugins have a design similar to the wordpress admin pages and relying on settings from other admin pages looks tricky !

comment:13 @ShaneF6 years ago

  • Keywords commit added; needs-testing removed

Again.. looks good. No error this time around.

comment:14 @Denis-de-Bernardy6 years ago

  • Keywords tested added

comment:15 @azaozz6 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [11144]) Let plugins use screen layout columns, props arena, fixes #9606

Note: See TracTickets for help on using tickets.