-
Notifications
You must be signed in to change notification settings - Fork 7
Convert [img] shortcodes back to tags/captions #31
base: master
Are you sure you want to change the base?
Conversation
Introduces a method to the Img_Shortcode_Data_Migration class to convert all the shortcodes added by this plugin back to the default WP format, and a WP-CLI command to access it.
…es-to-inline-images
Follow the much better naming conventions established in #34.
Sub `img_shortcode_regex()` for `img_tag_regex()`
Ok, got a clean build going, going to revisit tomorrow and work on more test coverage for the reverse conversion. |
I haven't run into these yet. Any pointers @goldenapples? Also would you mind suggesting additional test coverage after looking at the ones I committed? Also @danielbachhuber I don't think we are in habit of doing CLI test coverage, but let me know if you feel differently for this feature. |
* ## EXAMPLES | ||
* | ||
* ## Revert all Posts from the Image Shortcake syntax | ||
* wp image-shortcake migrate `wp post list --post_type=post` --ids` |
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.
s/migrate/revert
Nice! I think you found all of the weird bugs I had left in there 😄 and fixed them. Thanks! The Cadillac tests are a nice touch. I'm wondering if we need to account for cases where attributes in image tags are in a different order than is output by core. Currently the Also, WordPress will choke on any
We discussed this a while back, I think the decision was that WP-CLI is well-enough tested that we can consider it blackboxed. So long as the regex matches and the replacements long as the dat |
@goldenapples re: I think we have adequate test coverage of this in the test file, but if you see a different test to add lemme know. As for the mismatch between Image Shortcake and Core ordering of image attributes – I see two options.
Which do you prefer? or is there another option I'm missing? |
Hmm. I tried running On one post, missing attachment files mean no output at all in the replacements:
Where the attachment files exist, it works much better:
Trying to migrate again from that last one gives me nothing:
I'm not sure exactly how deep to get into this for this iteration. Using an HTML parser is an obvious solution and might be able to get around these problems. To a degree, though, these are edge case problems and it might be acceptable to leave them as open known issues until the plugin gets more use and we determine the use cases that are most important to support? |
Ah, ok, the no attachment bug makes sense to me due to the You can see the test stub I started here for the missing attachment issue. https://github.com/fusioneng/image-shortcake/pull/31/files#diff-d6837b978cabb03629279a82d2b08c60R121 This is a tough one for me. Because WordPress is using src files, it seems nonsensical to reverse a shortcode to an |
I guess that could work. Would |
Hey @goldenapples, see here where @danielbachhuber recommends that we use the If there's an attachment ID & a caption present, I'm still retaining that information in the element ID for the caption. If there's an attachment ID & no caption, there is a loss of information. So yeah, I think a |
Storing just the attachment ID sounds good. This way all isn't lost. These are edge cases where if you run into these cases, you have bigger problems already. The biggest case I wanted to avoid was where a shortcode would be replaced with an empty string, so that there was no possible recovering. Now we're always returning something, so if users find issues after running the CLI command, they can always reverse it using the CLI output. |
@goldenapples Yes, in theory... I think that means we need to make sure that the |
Do you think that's even feasible, given that the output is filterable in so many ways? |
Hm, I see what you mean re: filters. It'd be nice if we could confirm on a vanilla WP install that such a loop is doable. If we want to make the migration function as powerful as the callback in terms of customizability, then I suppose we'd need to add a filter or three to Agree with this? I guess next step would be adding a new site to my |
This seems like a simple test to set up, and yes, making sure this is possible without any other filters running would be a great thing to be sure of before shipping this feature.
👍 👍 |
Hm, actually, I think first I should add some more tests to |
Eh, maybe not, I didn't realize that |
Ok.. After playing with this on a new clean site, I think we should add some more test coverage to the regexes. @goldenapples, what's the right way to test these given that they are private methods? Should we make them public or do something else? |
Added some regex tests and temporarily changed the regexs to public while I work on getting them to pass. |
You could also test the |
Based on interactive testing here http://regexr.com/3bjdn
Ok, this is nearly there, but it's about closing time for me. The remaining test issue lies with |
@goldenapples Hey - mind adding me back to this repo? The failing tests were bothering me so I finished them off this morning... |
@davisshaver Thats freaking awesome! Doesn't look like I'm able to add collaborators to the repo, though. Might have to wait until @danielbachhuber gets back tomorrow for that? |
👍 |
@danielbachhuber Can you add me so I can push the final commit? |
Done — apologies for the delay. |
Thanks @danielbachhuber. @goldenapples, passing this one back to you. |
See #20.
Introduces a method to the Img_Shortcode_Data_Migration class to convert
all the shortcodes added by this plugin back to the default WP format,
and a WP-CLI command to access it.
Still needs tests. Also there are some edge cases which break it (mostly dealing with caption widths), which should be identified and fixed in tests.