X Theme Errors after upgrade - wp-comments page, Unexpected token

I have just upgraded to 5.2 and not able to click on Reply button in comments page of WP Comments. When I checked the console it looks like below . Console Error below are couple of lines.

Uncaught SyntaxError: Unexpected token < load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils&ver=5.2:10

We did not change anything. I have tried everything from disabling all plugins and testing it out…but no luck…finally posting here for help.
Also, our server team said that they noticed X theme errors as below

    PHP Fatal error: Uncaught Error: Call to undefined function cs_generate_data_attributes() in /home/xxx/public_html/wp-content/themes/x-child/functions.php:554
    Stack trace:
    #0 /home/xxx/public_html/wp-includes/shortcodes.php(325): x_shortcode_recent_posts_v2code(Array, '', 'x_recent_posts')
    #1 [internal function]: do_shortcode_tag(Array)
    #2 /home/xxx/public_html/wp-includes/shortcodes.php(199): preg_replace_callback('/\\[(\\[?)(x_rece...', 'do_shortcode_ta...', 'apply_filters('

Please help. We are stuck and not able to do many things on the Admin side like replying comments, even buttons do not work.

Hi @chinnailu,

This error message is most likely a plugin conflict issue. Please try testing a plugin conflict. You can do this by deactivating all third-party plugins, and see if the problem remains. If it’s fixed, you’ll know a plugin caused the problem, and you can narrow down which one by reactivating them one at a time.

If it doesn’t help, please rollback to the WordPress v5.1.1 to check if the issue persists:

Can you please provide the full code of x_shortcode_recent_posts_v2code function so we can take a closer look?

Thank you.

Thanks for the response. As I said, it is not a plugin issue as we have tried everything. The issue does not go away with disabling plugin.
Here is the code for the function in the Child Theme. Please review and advise.

// Add Excerpts to the recent post element
// =============================================================================
function x_shortcode_recent_posts_v2code( $atts ) {
  extract( shortcode_atts( array(
    'id'           => '',
    'class'        => '',
    'style'        => '',
    'type'         => 'post',
    'count'        => '',
    'category'     => '',
    'offset'       => '',
    'orientation'  => '',
    'show_excerpt' => 'false',
    'no_sticky'    => '',
    'no_image'     => '',
    'fade'         => ''
  ), $atts, 'x_recent_posts' ) );

  $allowed_post_types = apply_filters( 'cs_recent_posts_post_types', array( 'post' => 'post' ) );
  $type = ( isset( $allowed_post_types[$type] ) ) ? $allowed_post_types[$type] : 'post';

  $id            = ( $id           != ''     ) ? 'id="' . esc_attr( $id ) . '"' : '';
  $class         = ( $class        != ''     ) ? 'x-recent-posts cf ' . esc_attr( $class ) : 'x-recent-posts cf';
  $style         = ( $style        != ''     ) ? 'style="' . $style . '"' : '';
  $count         = ( $count        != ''     ) ? $count : 3;
  $category      = ( $category     != ''     ) ? $category : '';
  $category_type = ( $type         == 'post' ) ? 'category_name' : 'portfolio-category';
  $offset        = ( $offset       != ''     ) ? $offset : 0;
  $orientation   = ( $orientation  != ''     ) ? ' ' . $orientation : ' horizontal';
  $show_excerpt  = ( $show_excerpt == 'true' );
  $no_sticky     = ( $no_sticky    == 'true' );
  $no_image      = ( $no_image     == 'true' ) ? $no_image : '';
  $fade          = ( $fade         == 'true' ) ? $fade : 'false';

  $js_params = array(
    'fade' => ( $fade == 'true' )
  );

  $data = cs_generate_data_attributes( 'recent_posts', $js_params );

  $output = "<div {$id} class=\"{$class}{$orientation}\" {$style} {$data} data-fade=\"{$fade}\" >";

    $q = new WP_Query( array(
      'orderby'             => 'date',
      'post_type'           => "{$type}",
      'posts_per_page'      => "{$count}",
      'offset'              => "{$offset}",
      "{$category_type}"    => "{$category}",
      'ignore_sticky_posts' => $no_sticky
    ) );

    if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();

      if ( $no_image == 'true' ) {
        $image_output       = '';
        $image_output_class = 'no-image';
      } else {
        $image              = wp_get_attachment_image_src( get_post_thumbnail_id(), 'entry-cropped' );
        $bg_image           = ( $image[0] != '' ) ? ' style="background-image: url(' . $image[0] . ');"' : '';
        $image_output       = '<div class="x-recent-posts-img"' . $bg_image . '></div>';
        $image_output_class = 'with-image';
      }

       $excerpt = ( $show_excerpt ) ? '<div class="x-recent-posts-excerpt"><p style="color:initial;">' . preg_replace('/<a.*?more-link.*?<\/a>/', '', cs_get_raw_excerpt() ) . ' read more</p></div>' : '';

      $output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . '" href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( sprintf( __( 'Permalink to: "%s"', 'cornerstone' ), the_title_attribute( 'echo=0' ) ) ) . '">'
                 . '<article id="post-' . get_the_ID() . '" class="' . implode( ' ', get_post_class() ) . '">'
                   . '<div class="entry-wrap">'
                     . $image_output
                     . '<div class="x-recent-posts-content">'
                       . '<h3 class="h-recent-posts">' . get_the_title() . '</h3>'
                       . '<span class="x-recent-posts-date">' . get_the_date() . '</span>'
                           . $excerpt
                     . '</div>'
                   . '</div>'
                 . '</article>'
               . '</a>';

    endwhile; endif; wp_reset_postdata();

  $output .= '</div>';

  return $output;
}

// =============================================================================

add_action('wp_head', 'change_recent_posts_to_v2');
function change_recent_posts_to_v2() {
  remove_shortcode( 'x_recent_posts' );
  add_shortcode( 'x_recent_posts', 'x_shortcode_recent_posts_v2code' );
}
// =============================================================================

Hi,

Your code looks correct, would you mind providing us your wordpress and ftp login in Secure Note so we can take a closer look.

Thanks

I have just added to the secure note. Please review and help.

Hi @chinnailu,

  • I couldn’t see the JS error you mentioned in the previous reply anymore.

  • I only saw this error Uncaught TypeError: Cannot read property 'getAttribute' of null which is coming from your custom JS under Theme Options > JS:

/* Code for opening an iFrame for Insurance */
var _container = document.querySelector("#framedApp");

var $target = document.querySelector("#target");
var navPath = $target.getAttribute("href");
var newWindow;

function closeOnLoad(myLink) {	
  newWindow = window.open(myLink, "connectWindow", "width=600,height=400,scrollbars=yes");
  setTimeout(function() {
    newWindow.close();
    window.location.href = navPath;
  }, 100);
  return false;
}

var browserType = navigator.userAgent.toLowerCase();
var isSafari = function(){
	var flag = false;
	if(browserType.indexOf("chrome") === -1 && browserType.indexOf("safari") > -1) {
		flag = true;	
	}
	return flag;
};
var isMacChrome = function() {
  var isMac = navigator.appVersion.indexOf("Mac OS") > -1;
  var flag = false;
  if(browserType.indexOf("chrome") > -1 && isMac) {
		flag = true;	
	}
  return flag;
}

if(isSafari() || isMacChrome()) {
	$target.addEventListener("click",function(){  	
  	event.preventDefault();
    closeOnLoad('https://redbus2us.brokersnexus.com/');
    return false;
  })	
}
  • I also was able to click on the Reply button:
  • For the recent posts, I’ve added to this test page and I couldn’t see any error:

https://redbus2us.com/?page_id=5613

Can you please double check?

Thank you.

Hello,
The error is the WP admin area, please go to the wp-comments page and try to reply there, it will fail. Check the JS Console there.

Also, the JS code you put up above, I removed that.

Hi @chinnailu,

You could try testing for a plugin conflict. You can do this by deactivating all third party plugins, and seeing if the problem remains. If it’s fixed, you’ll know a plugin caused the problem, and you can narrow down which one by reactivating them one at a time.

You could also try switching your theme to the default Twenty Nineteen wordpress theme the check if the issue persists.

Let us know how it goes!

As I said, I have already done that. I have disabled all the plugins and then tried, still the issue exists. It is something to do with the theme only, hence seeking your support.

@paul.r, I see that it is fixed now. Did you do anything ? Please clarify.

Hi @chinnailu,

I didn’t do anyhting with regards to that. Glad to know it’s working now.

Have a great day! :slight_smile:

1 Like

It is weird, how it all worked again…Thanks for your support @paul.r, appreciate it !

You are most welcome. :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.