Make WordPress Core

Opened 8 years ago

Closed 6 years ago

#32137 closed enhancement (invalid)

Allow user-specified default image size when inserting image via Press This

Reported by: topdownjimmy's profile topdownjimmy Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.2
Component: Press This Keywords: has-patch
Focuses: Cc:

Description

Currently, when adding an image to a post in a Press This window, the image is inserted at full size by default. It would be helpful if the default insertion size could be specified by the user.

This is unrelated to Ticket #30269, as that concerns inserting images in the standard post editor.

Attachments (8)

default-press-this-image-size.patch (1.3 KB) - added by topdownjimmy 8 years ago.
Patch to apply image_default_size setting to Press This insertions
32137.2.patch (1.5 KB) - added by topdownjimmy 8 years ago.
Different method, interferes less with media_sideload_image()
32137.3.patch (1.7 KB) - added by topdownjimmy 8 years ago.
Fixing is_wp_error check in side_load_images
32137.4.patch (2.0 KB) - added by topdownjimmy 8 years ago.
Attempting a safer size- img class replacement with this patch
32137.5.patch (1.9 KB) - added by topdownjimmy 8 years ago.
Better handling of class attribute string
32137.6.patch (2.4 KB) - added by topdownjimmy 8 years ago.
Thanks for the feedback @stephdau.
32137.2.2.patch (1.5 KB) - added by topdownjimmy 8 years ago.
I think this may be a better approach for validating the output of wp_get_attachment_image_src? I'm not positive.
32137.7.patch (2.3 KB) - added by topdownjimmy 8 years ago.
FIX: I think this may be a better approach for validating the output of wp_get_attachment_image_src? I'm not positive.

Download all attachments as: .zip

Change History (14)

@topdownjimmy
8 years ago

Patch to apply image_default_size setting to Press This insertions

#1 @topdownjimmy
8 years ago

  • Keywords has-patch added

Patch attached, though there may be a more elegant way of accomplishing this.

@topdownjimmy
8 years ago

Different method, interferes less with media_sideload_image()

@topdownjimmy
8 years ago

Fixing is_wp_error check in side_load_images

@topdownjimmy
8 years ago

Attempting a safer size- img class replacement with this patch

#2 @topdownjimmy
8 years ago

Curiously, even without my patches, if the user specifies a custom class name in the Press This window, the size-full class name is overwritten (though alignnone remains).

@topdownjimmy
8 years ago

Better handling of class attribute string

#3 @topdownjimmy
8 years ago

  • Type changed from feature request to enhancement

#4 @stephdau
8 years ago

32137.5.patch should work,but:

  • please make sure to build your patches from the repository root: src/...
  • if ( $return === 'id' ) and if (get_option('image_default_size') != '' && get_option('image_default_size') != 'full') should use Yoda conditions.
  • $src_array[0] should be checked to make sure it has the expected value before using it.
  • preg_match( '/(class="[^"]+)"/', should check for both " and ' as attribute delimiters.
  • might as well instantiate a variable for get_option('image_default_size')
Last edited 8 years ago by stephdau (previous) (diff)

@topdownjimmy
8 years ago

Thanks for the feedback @stephdau.

@topdownjimmy
8 years ago

I think this may be a better approach for validating the output of wp_get_attachment_image_src? I'm not positive.

@topdownjimmy
8 years ago

FIX: I think this may be a better approach for validating the output of wp_get_attachment_image_src? I'm not positive.

#5 @azaozz
8 years ago

Couple of notes:

  • To do this properly (restrict the inserted image size) we will need to restrict it when first inserted, from JS. Otherwise the user will see the "full" image in Press This, and it will be replaced with the "default" size on saving. That difference can be pretty large, and definitely unexpected.
  • The option image_default_size hasn't been used for years. As far as I remember it is a left over from the old media modal, pre 3.5. Perhaps we could use get_user_setting('imgsize') which is the size the user selected when last inserting an image into the editor. However there's no way for the user to change that size in PT.

In that terms the current workflow seems better: insert the full image size (as found on the source site), and replace it with the same size on saving. If the user likes to change it, that can be done from the Edit Post screen in wp-admin, same as the rest of the more advanced settings.

Looking at 32137.7.patch, it seems like a good idea to return the attachment id from media_sideload_image(), then do wp_get_attachment_image() so the image tag has the proper class, etc. Then plugins will be able to use several of the image filters to change size or other attributes for the replacement image tag.

#6 @kraftbj
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

With PT being moved into a plugin, moving the conversation to https://github.com/WordPress/press-this/issues/5

Note: See TracTickets for help on using tickets.