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

wp-image-{ID} class for inserted attachments #1189

Open
pavelevap opened this issue Jan 26, 2017 · 5 comments
Open

wp-image-{ID} class for inserted attachments #1189

pavelevap opened this issue Jan 26, 2017 · 5 comments
Labels
discussion Needs discussion or is being discussed. scope: core Core VersionPress functionality like tracking actions, creating Git commits, etc.

Comments

@pavelevap
Copy link
Collaborator

When image (attachment) is uploaded and inserted into post, special class wp-image-{ID} is automatically applied.

image

But this ID will be preserved for example during restore even if no longer valid. I am not sure what should be done:

  • Nothing :-)
    But when somebody targets this ID in his CSS files, VP will break it.
  • Replace it
    It could be automatically replaced with the help of VPID, but it does not solve CSS problem.
  • Remove it
    It can be easily removed with get_image_tag_class hook which is probably good for new installations and new posts, but older posts have to be handled anyway.

Similar problem is also for caption shortcode.

@borekb
Copy link
Member

borekb commented Jan 26, 2017

This is indeed a big challenge and I'm not even sure it can have an automated solution – we might require plugin authors to avoid numerical IDs in templates, CSS files etc. For example, they could use a slug. That is unpleasant but I can't see how we could automatically replace IDs with VPIDs here.

The technical reason is that for database entities, VPID is their canonical identifier and in multiple environments, it can be represented by different autoincrement IDs just fine (MySQL database is a "cache" as far as VersionPress-powered site is concerned; it can be deleted at any time and restored from the Git repo).

But for files, what is in the repository is exactly copied to every working copy and we cannot have <img class="wp-image-10"> in one environment and <img class="wp-image-11"> in another, together with automated updates in all the CSS files etc. This would not only be tricky to implement but also Git would see all such files as modified. This is clearly bad.

@unclhos
Copy link
Contributor

unclhos commented Feb 1, 2017

No way to easily implement this with regex in the .versionpress files? Something like

post:
  regex:
    tag:
      atr: 
        prefix: id

in this case

post:
  regex:
    img:
      class:
        wp-image-: id

Then you could use the VPID in vpdb files.

@borekb
Copy link
Member

borekb commented Feb 2, 2017

@unclhos The problem is that someone might use the auto-increment ID in their CSS styles, PHP templates etc. So when we fix the ID in database entities using the VPID technique or the regex you suggest, their styling or whatever will be broken.

@unclhos
Copy link
Contributor

unclhos commented Feb 2, 2017

Why would you do it in the database? Wouldn't you just do it to the copy stored in the vpdb files like you do the siteurl?

Edit: ah, I see what you mean. Hmmmmmmm

@unclhos
Copy link
Contributor

unclhos commented Feb 2, 2017

Well really if you do nothing. Everything will work fine in this situation. Because 128 could be abc for all we care. If they use that id to target with css, then info will be the same everywhere. The problem only problem i would see is if they deleted the html and re-inserted it on a different location, then the ID would change and css would break. But they would probably just think that was a different image.

@borekb borekb added discussion Needs discussion or is being discussed. scope: core Core VersionPress functionality like tracking actions, creating Git commits, etc. labels May 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Needs discussion or is being discussed. scope: core Core VersionPress functionality like tracking actions, creating Git commits, etc.
Projects
None yet
Development

No branches or pull requests

3 participants