I'm a beginner self-made in coding. I've got a complexe theme which works well in wordpress since 2012. Since then some stuff didn't work anymore. Though I often use jqmigrate to change and correct what's needed to be changed or is deprecated. Tired of always changing stuff I've updated wordpress to adapt that theme from now.
I've got that new warning :
jQuery.parseJSON requires a valid JSON string
concerning that exact line :
hooks = jQuery.parseJSON(hooks);
in this part of code :
/**
* SMOF js
*
* contains the core functionalities to be used
* inside SMOF
*/
jQuery.noConflict();
/** Fire up jQuery - let's dance!
*/
jQuery(document).ready(function($){
jQuery("select.seo-select").children().removeAttr('selected');
jQuery("select.seo-select").change(function(){
$input = jQuery(this).parent().prev();
$text = jQuery(this).val();
if($input.val() != ''){
$text = ' | '+jQuery(this).val();
}
$input.val($input.val()+$text);
jQuery(this).children().removeAttr('selected');
});
//(un)fold options in a checkbox-group
jQuery('.fld').change(function() {
var $fold='.f_'+this.id;
$($fold).slideToggle('normal', "swing");
});
//delays until AjaxUpload is finished loading
//fixes bug in Safari and Mac Chrome
if (typeof AjaxUpload != 'function') {
return ++counter < 6 && window.setTimeout(init, counter * 500);
}
//hides warning if js is enabled
$('#js-warning').hide();
//Tabify Options
$('.group').hide();
// Display last current tab
if ($.cookie("of_current_opt") === null) {
$('.theme_options .group:first').fadeIn('fast');
$('.theme_options #of-nav li:first').addClass('current');
} else {
var hooks = $('#hooks').html();
hooks = jQuery.parseJSON(hooks);
if(hooks) {
$.each(hooks, function(key, value) {
if ($.cookie("of_current_opt") == '#of-option-'+ value) {
$('.theme_options .group#of-option-' + value).fadeIn();
$('.theme_options #of-nav li.' + value).addClass('current');
}
});
}
}
I haven't found response for that problem in other posts. Except one that seemed to be relevant. I've tried to add this at the top as adviced in https://stackoverflow.com/a/24512828/8844128 but it didn't change anything :
var json = $.parseJSON(jsonString || "null");
Maybe it's a different problem. Does anybody has an explanation and even better a valid solution I could use?
- jquery-migrate.js?ver=1.4.1:45
- jquery.js?ver=1.12.4:2
- wordpress : 4.9.4
- site : My Site
As asked in the comments it's used in the theme's admin option interface pages when you trigger the background image popup. Here are the admin code where hook
appears at line 159 :
jQuery.noConflict();
jQuery(document).ready(function($){
//hide hidden section on page load.
jQuery('#section-body_bg, #section-body_bg_custom, #section-body_bg_properties').hide();
//delays until AjaxUpload is finished loading
//fixes bug in Safari and Mac Chrome
if (typeof AjaxUpload != 'function') {
return ++counter < 6 && window.setTimeout(init, counter * 500);
}
//hides warning if js is enabled
$('#js-warning').hide();
//Tabify Options
$('.group').hide();
// Display last current tab
if ($.cookie("of_current_opt") === null) {
$('.group:first').fadeIn();
$('#of-nav li:first').addClass('current');
} else {
var hooks = <?php
$hooks = of_get_header_classes_array();
echo json_encode($hooks);
?>;
$.each(hooks, function(key, value) {
if ($.cookie("of_current_opt") == '#of-option-'+ value) {
$('.group#of-option-' + value).fadeIn();
$('#of-nav li.' + value).addClass('current');
}
});
}
and then at line 1190 :
$header_class = ereg_replace("[^A-Za-z0-9]", "", strtolower($value['name']));
$jquery_click_hook = ereg_replace("[^A-Za-z0-9]", "", strtolower($value['name']));
$jquery_click_hook = "of-option-" . $jquery_click_hook;
$menu .= '<li class="' . $header_class . '"><a title="' . $value['name'] . '" href="#' . $jquery_click_hook . '">' . $value['name'] . '</a></li>';
$output .= '<div class="group" id="' . $jquery_click_hook . '"><h2>' . $value['name'] . '</h2>' . "\n";
break;
Is there a way I can send the php file inline if it helps see how everything connects?