Make WordPress Core

Opened 11 years ago

Last modified 5 years ago

#23863 new defect (bug)

Post Formats: allow filtering content_width per format in wp-admin

Reported by: lancewillett's profile lancewillett Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Post Formats Keywords: needs-patch dev-feedback
Focuses: administration Cc:

Description

On front-end a theme can filter $content_width like so:

function twentythirteen_content_width() {
	if ( has_post_format( 'image' ) || has_post_format( 'video' ) ) {
		global $content_width;
		$content_width = 724;
	}
}
add_action( 'init', 'twentythirteen_content_width' );

But ... functions called in wp-admin that use the global $content_width variable won't be changed.

For example, using trunk and Twenty Thirteen theme:

  1. Create a new post, set to Image post format
  2. Click Add Media to insert an image
  3. Upload an image at least 800 px wide
  4. You'll see in "Attachment Display Settings" that width for the "large" size to insert to the post is 604 pixels and not 724.

Also, even if detecting a Post Format this way worked correctly on edit, it wouldn't work on first post creation because of how the UI uses JS to switch between the formats.

Attachments (2)

correct-width-in-editor.png (564.4 KB) - added by lancewillett 11 years ago.
incorrect-width-in-editor.png (565.1 KB) - added by lancewillett 11 years ago.

Download all attachments as: .zip

Change History (14)

#2 @lancewillett
11 years ago

This sort-of works:

/**
 * Resizes image restriction in wp-admin Media "large" size for video and image
 * post formats.
 *
 * @param array $dim Dimensions, height x width.
 * @param string $size Image size.
 * @param string $context 'edit' for wp-admin on 'display' for front-end.
 * @return array Resized dimensions to fit Twenty Thirteen's desired widths.
 */
function twentythirteen_test( $dims, $size, $context ) {
	/*
	@todo How to tell from wp-admin if we're in a Video or Image post format?
	And, if you click Add New to make a new post, then click one of the Post Format tabs ...
	how does the Media editor know you've switched?
	*/

	if ( 'large' == $size && 'edit' == $context )
		return array( 724, 724 );
}
add_filter( 'editor_max_image_size', 'twentythirteen_test', 10, 3 );

#3 @philiparthurmoore
11 years ago

  • Cc philip@… added

#4 @lancewillett
11 years ago

  • Component changed from Media to Post Formats
  • Keywords dev-feedback added

#5 @lancewillett
11 years ago

Possibly related to #23198, where TinyMCE uses get_post_format() to add a body class value to the editor.

#6 @DrewAPicture
11 years ago

This sounds sorta close to #21256. Same basic goal different application.

#7 @alexvorn2
11 years ago

  • Cc alexvornoffice@… added

#8 follow-up: @kovshenin
11 years ago

@todo How to tell from wp-admin if we're in a Video or Image post format? And, if you click Add New to make a new post, then click one of the Post Format tabs ... how does the Media editor know you've switched?

We can pass the current selected post format $('#post_format').val() to the query-attachments request that gets fired in media.model.Query.sync and then look for than in $_REQUEST. However, since the media modal saves its state when closed, changing the post format and re-opening media will show the already fetched attachments. We'd need to reset the collection and have it fetch attachments again, which I think is inefficient, but could work.

On the other hand, we can try and bring the content-width-based-on-post-formats logic into the js and resolve all of this client-side.

#9 in reply to: ↑ 8 @lancewillett
11 years ago

Replying to kovshenin:

On the other hand, we can try and bring the content-width-based-on-post-formats logic into the js and resolve all of this client-side.

A JS-based solution is fine by me.

#10 @nacin
11 years ago

My comment in #21256 questions whether changing content_width on the fly even makes sense. Just throwing that out there. It seems like content width needs to be separated from embed width.

#11 @ocean90
11 years ago

  • Milestone changed from 3.6 to Future Release

#12 @chriscct7
9 years ago

  • Focuses administration added
Note: See TracTickets for help on using tickets.