- This topic has 16 replies, 3 voices, and was last updated 5 years, 6 months ago by Tom.
-
AuthorPosts
-
September 19, 2018 at 5:09 am #681008kleintk
Hi,
I’m currently using GP Premium 1.7.2 and GeneratePress 2.1.4 utilizing the built-in Sections editor. My goal is to use the Preformatted formatting to display some example code. However, as soon as I click on “Update” or “Save Draft”, all backslashes are removed from my example code.
E.g.
value = b’\x0f\xfa\x34\x01′ # address
value += b’\x20\x29\x00\x44′ # port
Becomes:
value = b’x0fxfax34x01′ # address
value += b’x20x29x00x44′ # portIn the Paragraph formatting, additionally apostrophes are reformatted by this process. The first ‘ becomes a ’ and the second ‘ becomes a ′.
E.g.
value = b’\x0f\xfa\x34\x01′ # address
value += b’\x20\x29\x00\x44’ # port
Becomes:
value = b’x0fxfax34x01′ # address
value += b’x20x29x00x44′ # portWhile the latter issue is just mildly annoying, the issue with the removed backlashes is more of a problem.
The first problem only appears in the Sections Editor, it also doesn’t matter whether I use Visual or Text input option. If I don’t use sections, but the default editor, everything seems to work fine.
The issue with the apostrophes also appears in the default editor.Anyone knows a solution or workaround (ideally not involving another plugin) (at least for the backslash problem)?
Thanks!
September 19, 2018 at 8:51 am #681312TomLead DeveloperLead DeveloperHi there,
Very strange – I assume you’re wrapping your code in
<pre>
or<code>
tags?September 19, 2018 at 12:27 pm #681475kleintkHi Tom,
yes, I use
<pre>
for the highlighting. I just checked, the backslashes also get removed when using<code>
.
On a second host where I installed GP Premium and GeneratePress it is the same issue. Happens also with all plugins disabled except for GP.September 19, 2018 at 10:28 pm #681805TomLead DeveloperLead DeveloperHmm, not sure what’s going on here.
If you’re willing to test something, you can try opening:
wp-content/plugins/gp-premium/sections/functions/metaboxes/metabox-functions.php
Then find this line:
$section['content'] = sanitize_post_field( 'post_content', $data['content'], $post_id, 'db' );
And replace it with:
$section['content'] = $data['content'];
Does it fix the issue when you save?
September 19, 2018 at 11:53 pm #681833kleintkSadly that didn’t fix the issue.
I can send (how?) you the credentials to a test instance if necessary.
Escaping with\\
doesn’t work either, as in it works for the first time saving as there is only the first\
removed, but after the second time saving the second\
is also removed.September 20, 2018 at 10:18 am #682365TomLead DeveloperLead DeveloperInteresting, so the backslashes aren’t being stripped on save. Just to confirm, they are being stripped in the Dashboard as well? Or only on the front end?
September 20, 2018 at 10:48 am #682381kleintkIt has several levels of behaviour.
I write them in the sections editor and close it with “Apply”:if I click on “Preview”:
* backslashes are stripped from the frontend in the now opening preview tab
* however, backslashes are still there when I open the section again in the editorif I click on “Update” (or “Publish” at a new post):
* backslashes are stripped from the frontend
* backslashes also stripped from the editor when I open the section again (I guess thats what you mean with Dashboard?)September 20, 2018 at 11:11 am #682390DavidHello, the same thing happens to me.
In wordpress html/text editor, I write
<code> <div>Hola mundo </div> </code>
When I switch to the visual editor and go back to the html/txt editor:
<code></code> <div> Hola mundo </div>
September 20, 2018 at 10:56 pm #682705TomLead DeveloperLead DeveloperWeird, that change I mentioned should save the content to the database as-is – maybe there’s something built into WordPress that strips backslashes. I’ll have to dig into the core WP code to see if they do anything fancy with the regular editor to preserve them. I’m away from the office but will be heading back tomorrow.
David – that sounds like a different issue. Any chance you can open a new topic?
Thanks! 🙂
September 21, 2018 at 12:46 am #682751September 26, 2018 at 11:08 am #687059TomLead DeveloperLead DeveloperJust went deep into WP looking at what’s going on.
The reason this happens in Sections and not the post content is WordPress strips them in the
update_metadata()
function: https://wordpress.stackexchange.com/a/53339/90661The easiest way to handle this is to add double backslashes to your code. It’s not elegant, and it would have to be done before each save, which is a pain.
Another option is to run your Section content through
wp_slash()
, but unfortunately we don’t have a filter within the save function to do this so it’s update safe. You’d have to make the change to the core file after each plugin update. Let me know if you want to go this route.September 27, 2018 at 1:23 am #687419kleintkHi Tom,
thank you for going down the rabbit hole. Is there a way that might be implemented in a future version of Sections?
Adding a double backslash would be a possible solution for posts created and seldom edited. I guess I will go that way for the “stylish” posts with page-wide rows where I use Sections for.For the normal posts / pages with code examples I’ll probably default back to the normal WordPress editor then. Or do you know a lightweight alternative? Maybe the new Gutenberg?
Thank you 🙂
September 28, 2018 at 10:10 am #688772TomLead DeveloperLead DeveloperI’ll definitely look at adding a filter, but it may not be possible due to security reasons.
The code you can add to GPP is pretty simple if you want to try, it would just need to be repeated after updates (until I can figure out a safe filter).
September 29, 2018 at 3:59 am #689226kleintkYes I’d like to try that.
How often do those kind of updates happen? (GP updates or WP updates?)September 29, 2018 at 10:25 am #689479TomLead DeveloperLead DeveloperGP Premium updates would overwrite this change, so you’d need to reapply it after those updates (if we can’t add a filter).
To make the change, open this file:
wp-content/plugins/gp-premium/sections/functions/metaboxes/metabox-functions.php
Find this line:
$section = json_decode( stripslashes( trim($section) ), true);
And add this on the line below it:
$section = wp_slash( $section );
-
AuthorPosts
- You must be logged in to reply to this topic.