Hmm, based on the error maybe start by adding wp-includes/js to the comma-separated JS optimization exclusion list?
That didnt help. My current exclusion list is this:
wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js
I have managed to fix one of the issues. Probably the code used some sort of side effect or something, that with 5.5.1 didnt work anymore. Rewrote some of the code and now the reservation process works.
The error: “Uncaught reference error: wp not defined” remains unchanged tho
Sorry for all the editing. Your reply got me thinking again, and I realised you helped me out with another issue a while back. For that issue we needed a code snippet that disables autoptimize for my reservation process. If I disable that code, the error disappears. The snippet contains this code:
add_action('plugins_loaded','ao_defer_inline_init');
function ao_defer_inline_init() {
if ( get_option('autoptimize_js_include_inline') != 'on' ) {
add_filter('autoptimize_html_after_minify','ao_defer_inline_jquery',10,1);
}
}
function ao_defer_inline_jquery( $in ) {
if ( preg_match_all( '#<script.*>(.*)</script>#Usmi', $in, $matches, PREG_SET_ORDER ) ) {
foreach( $matches as $match ) {
if ( $match[1] !== '' && ( strpos( $match[1], 'jQuery' ) !== false || strpos( $match[1], '$' ) !== false ) ) {
// inline js that requires jquery, wrap deferring JS around it to defer it.
$new_match = 'var aoDeferInlineJQuery=function(){'.$match[1].'}; if (document.readyState === "loading") {document.addEventListener("DOMContentLoaded", aoDeferInlineJQuery);} else {aoDeferInlineJQuery();}';
$in = str_replace( $match[1], $new_match, $in );
} else if ( $match[1] === '' && strpos( $match[0], 'src=' ) !== false && strpos( $match[0], 'defer' ) === false ) {
// linked non-aggregated JS, defer it.
$new_match = str_replace( '<script ', '<script defer ', $match[0] );
$in = str_replace( $match[0], $new_match, $in );
}
}
}
return $in;
}
-
This reply was modified 6 years, 2 months ago by
jeroenm77.
Had a quick look, I’m not seeing wp not defined any more though?
I had the code snippet disabled to test it, and thus is dissappeared, I’ll enable the snippet again now
hmm, you could try changing
if ( $match[1] !== '' && ( strpos( $match[1], 'jQuery' ) !== false || strpos( $match[1], '$' ) !== false ) ) {
into
if ( $match[1] !== '' && ( strpos( $match[1], 'jQuery' ) !== false || strpos( $match[1], '$' ) !== false ) || strpos( $match[1], 'wp.' ) !== false ) ) {
Yes, that did the trick! Thanks so much again π