Skip to content

Instantly share code, notes, and snippets.

@joemcgill
Created December 10, 2015 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joemcgill/eb3c68c8f3b1ec3dca27 to your computer and use it in GitHub Desktop.
Save joemcgill/eb3c68c8f3b1ec3dca27 to your computer and use it in GitHub Desktop.
Random notes while thinking about the RICG merge into 4.4

WP RICG Images merge notes

  • Consider merging get_image_tag() and wp_get_attachment_image().
    • Nah, bad idea. While get_image_tag() is only used in the media editor, it probably makes sense to keep the image generation on the back end and front end separated because of how people are likely filtering display.
  • Add an event listener to the editor if we can't do a content filter.
    • Look into adding needed metadata directly to wp.media to avoid the ajax request
  • Add caching to attachment_url_to_postid to speed up multiple requests.
  • Add smart ways to filter sizes globally w/o inducing another wp_get_attachment_image() call.

TinyMCE Updates

  • We might be able to set the srcset and sizes attributes directly in the updateImage function in wpeditimage/plugin.js
  • imageData still contains meta from the original image being replaced instead of the new image being inserted. UPDATE: not true. It just doesn't update the customWidht/customHeight properties.
  • We have an id, size, and width right there in imageData, so we should be golden.

This is what needs to happen:

On update, see if this is a different image and, if so:

  • Use the id to retrieve intermediate sizes
  • Check aspect ratio against our aspect ratio property
  • Build the srcset attribute
  • Build a sizes attribute

Questions to resolve:

  • How do we get the intermediate sizes for an image, now that we have the id since that data isn't passed to the tinyMCE editor as far as I can tell?
  • We need to update the sizes attribute after the image is resized using the corner handles in MCE

How to filter

  1. Get all the images including the uploads dir.
  2. Get id & size. a) check via class attributes b) parse the src url directly
  3. retrieve srcset and sizes attributes
  4. rewrite HTML and return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment