coffee2code / wpuntexturize

A plugin for WordPress that prevents WordPress from displaying single and double quotation marks as their curly alternatives.
GNU General Public License v2.0
2 stars 1 forks source link

[request] add Settings entry for configuration? #1

Closed James-E-A closed 4 years ago

James-E-A commented 4 years ago

I, unfortunately, confirmed this bug on:

James-E-A commented 4 years ago

To be clear, the content of the demo post is below:

quotes demo—“ ” " ' ‘ ’

quotes demo—“ ” " ' ‘ ’

but it's being rendered as:

quotes demo—" " " ' ' '

coffee2code commented 4 years ago

Thanks for the report!

However, this is a feature of the plugin as of v1.7. See 17450b4. The first paragraph of the plugin's extended description had been amended at that time to say:

If your content happens to already have curly quotation marks in it, then this plugin also converts them to their non-curly alternatives.

Does the current behavior cause a problem with how you've been using the plugin, or is it just something you weren't expecting it to do? (i.e. it affects text in a way you don't want it to versus its behavior wasn't documented clearly enough?)

If the former, how are you using the plugin? The use-case would imply that you may be copy-and-pasting curly quotes into posts and want those retained, but when directly typing quotes you don't want those converted to curly quotes?

James-E-A commented 4 years ago

Does the current behavior cause a problem with how you've been using the plugin

Yes—in fact, I noticed it when I had a post in which I (for some reason or another) had intentionally mixed the quote styles.

I'd originally thought the theme of this plugin was what-you-write-is-what-you-get: I had installed it under the impression it'd give me, the writer, more control over what I publish, without WordPress interfering and artificially normalizing my text in a way outside of my control.

I see on the Changelog you've listed:

New: Convert native curly quotation marks to their non-curly alternatives New: Add filter c2c_wpuntexturize_convert_curly_quotes to allow disabling of conversion of native curly quotes

—however, this plugin seems to have no Settings item on the admin panel.

Would setting that pseudo-configuration option require manually editing Theme files or PHP files each Theme/WordPress update, respectively?

coffee2code commented 4 years ago

I'd originally thought the theme of this plugin was what-you-write-is-what-you-get

That was indeed the original intent. However, I think the more common expectation of the plugin is to completely eliminate the appearance of curly quotes, whether they were originally present or swapped in by WP. I acknowledge the one-liner plugin description should also be updated to reflect this.

But that's why I was curious about your use-case, since I wasn't sure of a real-world scenrio which warranted usage of both styles of quotes.

Would setting that pseudo-configuration option require manually editing Theme files or PHP files each Theme/WordPress update, respectively?

As you discovered, there is a hook that can be used to prevent the plugin from uncurling pre-existing curly quotes. I did not add an input setting to the admin as I wasn't convinced there was be a minimum threshold of users to warrant adding one. However, via the hook it's a one-line piece of code to do what you want.

I generally recommend putting custom code in a site-specific plugin. You can search the web for details for how to create one, but basically

  1. create the sub-directory mu-plugins in your site's wp-content directory, unless it already exists
  2. create a file for the code (e.g. site.php or customize-wpuntexturize.php) within mu-plugins.
  3. the file should have <?php as its first line
  4. on the 3rd line or later, add the code. In this case, you'll want to add this:
// Don't convert curly quotes into non-curly quotes.
add_filter( 'c2c_wpuntexturize_convert_curly_quotes', '__return_false' );

There are other ways of adding that line of code (which I preceded with a code comment so in the future you know what that code is doing), but that's the most future-proof. You don't have to make any further changes once it's done. It'll persist after WP updates, updates to the plugin, updates to your theme, or a theme change. If you disable the plugin in the future, that ine of code won't cause your site any problems.

Let me know how it goes or if you have any questions.

James-E-A commented 4 years ago

./wp-content/mu-plugins/wpuntexturize.php

has done it! (I decided to insert a link to this thread in as a comment, to provide maximal context.) This is certainly better than having to hand-patch regularly, but I don't think it's the correct solution.

I'll see if I can't get a PR knocked out by Saturday to set at least this, possibly some of the other 3 configurables, from within WordPress' built-in plugin configuration "Settings" UI.

James-E-A commented 4 years ago

I've…got no idea why this isn't working: https://github.com/JamesTheAwesomeDude/wpuntexturize/commit/c427a39cbf2b690c9d9351faab5de71c34d60fd8

The documentation on the Settings API is a pedantic mess, so I tried to just template it off the file from a known-good plugin. But it's not even showing the UI element, for some inscrutable reason.

coffee2code commented 4 years ago

...but I don't think it's the correct solution.

Creating a mu-plugin is a perfectly valid way of having code that customizes a plugin, theme, or WP itself. Not every circumstance can be expressed with having a setting UI, and even if it can, there's the consideration of whether a setting should even be made available (see WordPress's philosophy of "Decisions, not options").

That said, you've gotten me to come around on the matter. I'll add a setting UI to control the behavior in the next release of the plugin. In fact, I've basically already implemented it (locally). I just need to add documentation, a screenshot, and a few other minor unrelated updates.

In the meantime, since the mu-plugin code works for you, I'd leave things at that for now. I'll follow up with this ticket once the code gets committed.

coffee2code commented 4 years ago

@JamesTheAwesomeDude: Hey James,

I've just released v2.0 of the wpuntexturize plugin which now includes a setting (found on the Settings -> Reading admin page) that allows you to enable or disable conversion of curly quotes in posts to their non-curly alternatives. As you've made me see the light about it, the setting is disabled by default (so that existing curly quotes are not affected, which was pre v1.7 behavior).

Earlier I had recommended creating a mu-plugin to use a filter to disable the feature. You can safely remove that file now. But don't worry, there will be no issues if the file remains. (However, the code in the file will override whatver is set via the plugin's setting, though in practice that's not likely to matter to you.)

Thanks again for the request! Let me know if you have any issues.