I did a migration of my WP website – transfered all files and database, configured the settings, updated the urls. Everything is working ok, except one specific database entry: wp_options et_divi, which is where the theme stores some custom metadata and other theme settings.
The problem is that, when I update any of the settings stored in this field, it gets stored with all the html tags and other codes removed/changed.
For example, this Analytics code:
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'xxxxxxxx', 'auto');
ga('send', 'pageview');
</script>
Is being stored like this:
s:409:"
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'xxxxxxxx', 'auto');
ga('send', 'pageview');
";
All the HTML tags are being removed and some slashes are being incorporated.
I think this can be a format/coding issue, but I really don’t know what to do. When I backuped the database I chosen the PhpMyAdmin quick export option with SQL format, and when I restored it in the new server, I used the import option with utf-8, SQL format, and NONE SQL compatibility mode options.
But note that it only gets messed when I update any entry inside this field (through the theme’s settings page – if I manually restore the field, everything gets back to normal).
So, anyone knows what can be happening here?
Update 1: I tried to deactivate all plugins and custom functions, but the same keeps happening.
Update 2: This is the array which stores the form field to the “body code integration”, used for the Google Analytics code above (file is options_divi.php):
array( "name" => esc_html__("Add code to the < body > (good for tracking codes such as google analytics)",$themename),
"id" => $shortname."_integration_body",
"type" => "textarea",
"std" => "",
"desc" => esc_html__("Any code you place here will appear in body section of all pages of your blog. This is usefull if you need to input a tracking pixel for a state counter such as Google Analytics.",$themename)
),
Update 3: And this is the header (beginning) of the file above (options_divi.php). I don’t know if it can help, but some terms like “htmlspecialchars” gotten my attention (don’t know if it is valuable, anyway).
<?php
global $epanelMainTabs, $themename, $shortname, $options;
$epanelMainTabs = array('general','navigation','layout','ad','seo','integration','support');
$cats_array = get_categories('hide_empty=0');
$pages_array = get_pages('hide_empty=0');
$pages_number = count($pages_array);
$site_pages = array();
$site_cats = array();
$pages_ids = array();
$cats_ids = array();
foreach ($pages_array as $pagg) {
$site_pages[$pagg->ID] = htmlspecialchars($pagg->post_title);
$pages_ids[] = $pagg->ID;
}
foreach ($cats_array as $categs) {
$site_cats[$categs->cat_ID] = $categs->cat_name;
$cats_ids[] = $categs->cat_ID;
}
$shortname = esc_html( $shortname );
$pages_ids = array_map( 'intval', $pages_ids );
$cats_ids = array_map( 'intval', $cats_ids );
$options = array ( //... the code goes on with the options arrays
If you need any more code/info, just let me know 🙂