Skip to content
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

Improvements to attachment and image classes #2785

Open
gchtr opened this issue Jul 31, 2023 · 0 comments
Open

Improvements to attachment and image classes #2785

gchtr opened this issue Jul 31, 2023 · 0 comments

Comments

@gchtr
Copy link
Member

gchtr commented Jul 31, 2023

In #2753, @nlemoine mentioned quite a few points we can improve in the file and attachment classes in a future version of Timber. I’m adding these as a separate issue so we don’t lose track of it.

Things to consider:

  • Remove path() methods in all models. Same reason as n°1 mentioned above: I don't think models need this method. If you want a relative path for something (src, link, etc.): use the relative filter or use a WP filter/plugin. Plus I don't think we need a helper to get the relative URL, there's already one in WP.
  • Do you know what's the abs_url for?
    public $abs_url;

    This feels redundant with $image->src()
  • I think we should remove the maybe_secure_url helper. If the URL is http, then it's a somewhere else problem that will be hidden (and not fixed and brought to the developer attention) by this fix that's not Timber in Timber's scope IMHO.
  • Same goes for remove_double_slashes: we shouldn't aim at fixing every issues whose causes are elsewhere in the stack.

and

  • image dimensions are still read from file, which could be avoided by getting image metadata for registered sizes and improve performance. But would require quite some refactoring (ImageDimensions doesn't takes some $metadata to look for dimensions)

  • I noticed that ImageHelper::sideload_image() is very optimistic 😅 There are some places in that method that can go wrong and are not handled:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant