• Resolved gheaven

    (@gheaven)


    The [hover] shortcode stops working on wordpress 6.0.2

    Double Ampersands within script tags are being encoded to & since WordPress 6.0.2
    e.g.

    if ((a._map != null && a._map._leaflet_id == map_id) ||
    				 	a._map == null ) {

    gets output as
    if ((a._map != null && a._map._leaflet_id == map_id) ||
    a._map == null ) {
    (i.e. with the second amersand sent as hash-zero-three-eight-semicolon)
    and generates a console error within the browser.`

    I would log it with the wordpress folk but cannot work out how. You may have a way of changing the logic to avoid the AND test and thus have a work around but I suspect you are not alone here.

    I note previously in earlier versions of wordpress / gutenberg this was an issue that got resolved about version 5.7

    • This topic was modified 2 years, 5 months ago by gheaven.
Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author hupe13

    (@hupe13)

    The error must be caused by a plugin you are using (caching plugin?) or something else. Are you using the standard editor? && is used quite often in the Javascript code and not only for hover.
    Working example.
    (On the english site the Plugins GitHub version is running, it is unstable. But the WordPress version of the plugin ist running on the german site. On both sites is no problem with this.)

    • This reply was modified 2 years, 5 months ago by hupe13. Reason: typo
    Thread Starter gheaven

    (@gheaven)

    Agree with the && being common.

    This is running in a clean install of WordPress 6.0.2 on Local and with no other plugins. Only the instance in that if statement with nested conditions is impacted. All the other && instances render properly. I even commented out the Jshrink and the problem persists.

    I will try and write my first ever minimal shortcode and see if I can reproduce it. I don’t think it is your problem.

    I will leave it open for now as you may need to re-factor as a work around

    Thread Starter gheaven

    (@gheaven)

    I have managed to do a minimal test that reproduces the problem. It only is a problem for an if statement nested in a for loop it seems.

    I made a minimal shortcode and noted in the comments.

    add_shortcode( 'test_ampersand', 'test_ampersand' );
    function ta_init(){
     function test_ampersand() {
    	$text = '<script>';
    	ob_start();
      ?>/*<script>*/
      if (1==1) {
    	if ((1 != 2 && 2==2 ) || 3==3) { null}
      } // Works
      for (var i=0; i < 2; i++) {
    	  if (1==1) {
    		if ((1 != 2 && 2==2 ) || 3==3) { null}
    	  }
      } // Does not work
      if (1==1) {
    	if ((1 != 2 && 2==2 ) || 3==3) { null}
      } // does not work now...
      <?php
      $javascript = ob_get_clean();
    	$text = $text . $javascript . '</script>';
    	return "\n".$text."\n Some Text";
     }
    }
    add_action('init', 'ta_init');
    

    I will raise a gutenberg bug now.

    Plugin Author hupe13

    (@hupe13)

    I have only been able to recreate this with Laragon under Windows. Both with php74 and with php81. On my hoster under Linux it works.

    Thread Starter gheaven

    (@gheaven)

    Plugin Author hupe13

    (@hupe13)

    Solution found here:

    in php/hover.php:

    $text = '<script><!--';
    ...
    $text = $text . $javascript . '//-->'."\n".'</script>';

    The problem only exists with Laragon and Windows.
    What is your environment? Does this work for you?

    Thread Starter gheaven

    (@gheaven)

    I develop on a windows 10 box and deploy to hosted linux so this is very useful.

    I vaguely recall the advice to enclose javascript in non properly formed block comments in PHP (or was it ASP) somewhere years ago (like almost last century). Thanks for taking the time on this.

    Thread Starter gheaven

    (@gheaven)

    But no, the problem still persists. I will keep an eye on the issue I raised in the wordpress world.

    If this becomes a huge problem for me I will refactor that script out to a js file and submit a pull request to you. Other fish are on my plate at the moment.

    Thread Starter gheaven

    (@gheaven)

    Undo that last comment, It does work.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Hover Broken from WordPress 6.0’ is closed to new replies.