Opened 12 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 | 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:
- Create a new post, set to Image post format
- Click Add Media to insert an image
- Upload an image at least 800 px wide
- 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)
Change History (14)
#2
@
12 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 );
#5
@
12 years ago
Possibly related to #23198, where TinyMCE uses get_post_format()
to add a body class value to the editor.
#8
follow-up:
↓ 9
@
12 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
@
12 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.
See also #23824 and #23620.