-
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
Consider path filtering for images in content. #190
Comments
If an image were uploaded elsewhere, could we reasonably infer that other
sizes exist?
|
cc: @bradt |
@tevko I don't understand the question. |
@bradt I believe he's asking if it's possible to identify the Attachment ID of an image that's been moved offsite, when the uploads directory remains on the server. And if not, how would we determine the other available image sizes to include in the |
We should try to address this before a core merge, if possible. |
The full filter in /**
* Filter the uploads directory data.
*
* @since 2.0.0
*
* @param array $uploads Array of upload directory data with keys of 'path',
* 'url', 'subdir, 'basedir', and 'error'.
*/
$uploads = apply_filters( 'upload_dir',
array(
'path' => $dir,
'url' => $url,
'subdir' => $subdir,
'basedir' => $basedir,
'baseurl' => $baseurl,
'error' => false,
) ); |
That's what I was thinking too, but I wasn't sure if @bradt had a use case where this wouldn't be the case. |
Yes, there is, as I described here: #177 (comment) |
I'll lay it out in more detail... Let's say you have a site with a bunch of existing media, but you want to start offloading any NEW media to S3. You could install WP Offload S3 (free version) and do just that. Now your new content will have S3 URLs and old content will have URLs to your server. In that case, you're going to want RICG to look for both S3 URLs and URLs to your local server. |
Important to get this one right. Easier to add a filter than move it later, so I'm moving it off this milestone for now. |
I'm glad you caught this, it occurred to me after the event filtering the regex would have an affect on the matches array & may cause problems with reset of the function. Some random thoughts:
|
This is exactly what I've been thinking. Currently, the callback only works if we can parse the I'll add a PR with the code for how this could work shortly. |
Now that we're no longer using a `preg_replace_callback` function in `tevkori_filter_content_images()`, it doesn't make as much sense to use the callback function the way we originally set it up. However, rather that merging the two function, this turns the callback into a useful utility function that accepts an `img` element and returns the HTML including `srcset` and `sizes` attributes if we can. Additionally, since we only add `srcset` and `sizes` when we're able to parse the attachment id from the markup, we also no longer need to limit our matches in the content filter by files containing the path to our uploads folder. This resolves #190.
Now that we're no longer using a `preg_replace_callback` function in `tevkori_filter_content_images()`, it doesn't make as much sense to use the callback function the way we originally set it up. However, rather that merging the two function, this turns the callback into a useful utility function that accepts an `img` element and returns the HTML including `srcset` and `sizes` attributes if we can. Additionally, since we only add `srcset` and `sizes` when we're able to parse the attachment id from the markup, we also no longer need to limit our matches in the content filter by files containing the path to our uploads folder. This resolves #190.
Now that we're no longer using a `preg_replace_callback` function in `tevkori_filter_content_images()`, it doesn't make as much sense to use the callback function the way we originally set it up. However, rather that merging the two function, this turns the callback into a useful utility function that accepts an `img` element and returns the HTML including `srcset` and `sizes` attributes if we can. Additionally, since we only add `srcset` and `sizes` when we're able to parse the attachment id from the markup, we also no longer need to limit our matches in the content filter by files containing the path to our uploads folder. This resolves #190.
Now that we're no longer using a `preg_replace_callback` function in `tevkori_filter_content_images()`, it doesn't make as much sense to use the callback function the way we originally set it up. However, rather that merging the two function, this turns the callback into a useful utility function that accepts an `img` element and returns the HTML including `srcset` and `sizes` attributes if we can. Additionally, since we only add `srcset` and `sizes` when we're able to parse the attachment id from the markup, we also no longer need to limit our matches in the content filter by files containing the path to our uploads folder. This resolves #190.
Now that we're no longer using a `preg_replace_callback` function in `tevkori_filter_content_images()`, it doesn't make as much sense to use the callback function the way we originally set it up. However, rather that merging the two function, this turns the callback into a useful utility function that accepts an `img` element and returns the HTML including `srcset` and `sizes` attributes if we can. Additionally, since we only add `srcset` and `sizes` when we're able to parse the attachment id from the markup, we also no longer need to limit our matches in the content filter by files containing the path to our uploads folder. This resolves #190.
Now that we're no longer using a `preg_replace_callback` function in `tevkori_filter_content_images()`, it doesn't make as much sense to use the callback function the way we originally set it up. However, rather that merging the two function, this turns the callback into a useful utility function that accepts an `img` element and returns the HTML including `srcset` and `sizes` attributes if we can. Additionally, since we only add `srcset` and `sizes` when we're able to parse the attachment id from the markup, we also no longer need to limit our matches in the content filter by files containing the path to our uploads folder. This resolves #190.
Now that we're no longer using a `preg_replace_callback` function in `tevkori_filter_content_images()`, it doesn't make as much sense to use the callback function the way we originally set it up. However, rather that merging the two function, this turns the callback into a useful utility function that accepts an `img` element and returns the HTML including `srcset` and `sizes` attributes if we can. Additionally, since we only add `srcset` and `sizes` when we're able to parse the attachment id from the markup, we also no longer need to limit our matches in the content filter by files containing the path to our uploads folder. This resolves #190.
…dates Refactor display filtering functions Now that we're no longer using a preg_replace_callback function in tevkori_filter_content_images(), it doesn't make as much sense to use the callback function the way we originally set it up. However, rather that merging the two function, this turns the callback into a useful utility function that accepts an img element and returns the HTML including srcset and sizes attributes if we can. Additionally, since we only add srcset and sizes when we're able to parse the attachment id from the markup, we also no longer need to limit our matches in the content filter by files containing the path to our uploads folder. This resolves #190.
When we filter the HTML of images in posts, we only do so if the image path matches the value of
wp_uploads_dir()
. We may need to keep in mind cases where a developer would want to filter images that have been uploaded somewhere else (e.g. S3).See: #177 (comment)
The text was updated successfully, but these errors were encountered: