-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use content filtering instead of the image editor #144
Use content filtering instead of the image editor #144
Conversation
I used an anonymous function in |
if ( $size ) { | ||
$size = $size[1]; | ||
|
||
// Otherwise create an array with the values from the width and height attributes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if there's no wp class or width / height attribute in the image html?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have to double check the source code but I believe the wp-image-*
class and width
and height
attributes are always present. Of course we could implement a check and do nothing if they are not there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jaspermdegroot there are often cases where the developer chooses to remove the WordPress classes and w/h attributes. Would we be able to retrieve the image ID if those weren't present? Or does this function fire with a higher priority, so that our calculations happen before theme customizations kick in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would we be able to retrieve the image ID if those weren't present?
No, I don't think so.
Or does this function fire with a higher priority ...
No, actually the priority is currently very low (999).
We can consider to make the priority very high instead of low, but we probably should add a check anyway to see if the image id and size could be retrieved from attributes and bail if not.
Uses DOMDocument to find images, then pulls the image ID from the `wp-image-*` class (could switch to whatever content filtering is used for ResponsiveImagesCG#144, so we’re not reliant on something that might be disabled). Generate the srcset, add it to the image tag, and update the post.
Uses DOMDocument to find images, then pulls the image ID from the `wp-image-*` class (could switch to whatever content filtering is used for ResponsiveImagesCG#144, so we’re not reliant on something that might be disabled). Generate the srcset, add it to the image tag, and update the post.
Uses DOMDocument to find images, then pulls the image ID from the `wp-image-*` class (could switch to whatever content filtering is used for ResponsiveImagesCG#144, so we’re not reliant on something that might be disabled). Generate the srcset, add it to the image tag, and update the post.
51ce34b
to
8b9bf7e
Compare
fd6b821
to
c1f1599
Compare
c1f1599
to
44e1cfd
Compare
I did an A/B performance test. Server:
Tool:
WordPress:
WordPress installation A uses the plugin as it is; using the image editor to insert the All images in this test have 3 sources available for the The results, based on 3 runs: Test post "Light" with 1271 words and 5 images:
Difference: Test post "Heavy" with 18 words and 25 images:
Difference: Test post "Very heavy" with 5020 words and 50 images:
Difference: Update: I ran the test again. The old (strikethrough) results for B are based on using |
44e1cfd
to
738c4e6
Compare
…cset attributes Fixes ResponsiveImagesCGgh-83 Fixes ResponsiveImagesCGgh-72
738c4e6
to
2740404
Compare
That would be nice indeed, but I would need help with that because I don't really see how we can do that.
Agreed
Good idea
A priority of 5 sounds good |
If we did a single |
No, we don't need the image size class because we can grab the values from the height and width attributes |
Good point. So we could slim it down to 2 regex matches but that's about it. |
Yes, we can reduce it to 2 |
what happens if the height and width attributes are missing? |
Then we bail |
Per discussion on Slack I changed the code to use |
The Not sure if that's a good idea in regards to merging into core. What do you think? |
@jaspermdegroot would this cause any issues for multisite installations? |
@jaspermdegroot I think it would be smart to do a sanity check on the file path before passing a url to Another thing I noticed is that an edited image may have a filename that doesn't match the value of |
Are you able to include a filter to get child attachments with the original selects on Some benchmarks would probably be in order, my instinct is it would be quicker but data would be better :). |
@peterwilsoncc That's a really interesting approach. I may be mistaken, but don't attachments have to be uploaded from that particular post's edit screen in order to show up as an attachment? In other words, if someone uploaded an image directly to the media library and then inserted it into a post, would it still show up in the list of attachments for that post? |
@joemcgill - that's correct, it would only save requests if the author's workflow was to upload the image from the post screen. At present it looks like there are three SQL calls per image: # attachment_url_to_postid
SELECT post_id FROM wp_postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = '2014/07/4000.png'
# tevkori_get_srcset_array
SELECT * FROM wp_posts WHERE ID = 16 LIMIT 1
SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (16) ORDER BY meta_id ASC Getting attachments as part of the original call should remove the second one for most images, possibly the third - I'll need to do some Nasty Hacks to check. It could also be mitigated by updating I'm slowly coming around to the idea of dynamically adding the srcset, avoiding extra SQL requests on each image/loop would probably convince me. |
I think while its a good idea to do a performance test on 5.6, I think it'd be really prudent to also do one for 5.2. Some of the performance benefits you might see running it on 5.6, might not exist (and in fact a patch could easily be a performance detractor on 5.2). While that's unlikely, confirming that's not the case is probably a good idea. |
Is there any particular part in the code that makes you think this could cause issues with multisite installations? Update: Our unit tests do test multisite and test pass so it shouldn't be a problem. |
Ok
I think we should try to handle those cases, but it doesn't feel rock solid to simply strip any "-e" followed by 13 digits from the end of the file name since it's perfectly valid to upload an image with that pattern in the filename. Probably an edge case but still. |
The extra SQL request was also my concern when we discussed using the url to get the ID instead of grabbing it from the class name and tests do show that is a bit slower, but I agree with @tevko and @joemcgill that it is more reliable. If we can avoid the extra request that would be great. Thanks for your input @peterwilsoncc . I will look into your approach. |
Good point. I will test performance against PHP 5.2 as well. |
I've done some work going directly from the image URLs to getting the attachment objects. It has less DB calls but whether it is more efficient overall will need further benchmarking. I've been working on the branch peterwilsoncc:content-filtering-pwcc [diff with jaspermdegroot:content-filtering] Callback is now in a class which requires a separate instance for each post, there's some shuffling around to make sure all image sizes return an ID, all of this leads me to question how efficient it is. All in all, not sure how much help this has been for y'all. |
This PR has been replaced by #170 |
See #83
Update: This PR has been replaced by #170