Код больше не работает: jQuery.parseJSON требует допустимой строки JSON
Я новичок, самостоятельно сделанный в коде. У меня сложная тема, которая хорошо работает в WordPress с 2012 года. С тех пор некоторые вещи больше не работают. Хотя я часто использую jqmigrate, чтобы изменить и исправить то, что нужно изменить или устареть. Надоело постоянно менять вещи Я обновил WordPress, чтобы адаптировать эту тему с этого момента.
Я получил это новое предупреждение:
jQuery.parseJSON требует допустимой строки JSON
относительно этой точной линии:
hooks = jQuery.parseJSON(hooks);
в этой части кода:
/**
* 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');
}
});
}
}
Я не нашел ответа на эту проблему в других сообщениях. За исключением того, что казалось актуальным. Я попытался добавить это вверху, как советовали в /questions/47958284/forma-soobscheniya-s-preduprezhdeniem-posle-obnovleniya-jquery/47958334#47958334 но это ничего не изменило:
var json = $.parseJSON(jsonString || "null");
Может быть, это другая проблема. У кого-нибудь есть объяснение и даже лучше правильное решение, которое я мог бы использовать?
- JQuery-migrate.js вер = 1.4.1: 45
- jquery.js вер =1.12.4:2
- WordPress: 4.9.4
- сайт: Мой сайт
Как было сказано в комментариях, он используется на страницах интерфейса опций администратора темы, когда вы запускаете всплывающее окно с фоновым изображением. Вот код администратора, где hook
появляется в строке 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');
}
});
}
а затем в строке 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;
Есть ли способ, которым я могу отправить встроенный файл php, если он помогает увидеть, как все соединяется?