Make WordPress Core

Opened 8 years ago

Closed 7 years ago

#35770 closed defect (bug) (duplicate)

Shortcode fails with 4.4. It is working with 4.3

Reported by: dezio1900's profile dezio1900 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.4.1
Component: Shortcodes Keywords:
Focuses: Cc:

Description

It appears that only this shortcode fails. I am using WP 4.4.2

Shortcode source(real source is not important, because it fails with this too):

<?php
// CONTENT WITH IMAGE
        add_shortcode( 'content_with_image', function( $atts, $shortcode_content = '' ){
                
                $options = shortcode_atts( array(
                        'image_position' => 'left',
                        'image_size' => 'medium',
                        'image_id' => '',
                        'image_link' => '',
                        'content_margin_top' => '0',
                        'title' => '',
                        'title_tag' => 'h3',
                        'allow_content_below_image' => 'no',
                        'margin' => '40px 0',
                ), $atts );
                
                return 'shortcode content';
                
        });

The shortcode is used this way:

[content_with_image image_position="left" image_id="198" content_margin_top="0" title="EXPERIENCED GUIDES" allow_content_below_image="no"]

Shortcode content

[/content_with_image]

So I had to overwrite /wp-includes/shortcodes.php with content from v4.3, in order for shortcode to work again.

Attachments (2)

35770.php (1015 bytes) - added by aaroncampbell 8 years ago.
MU plugin for testing
35770.2.php (1.7 KB) - added by aaroncampbell 8 years ago.
MU plugin for testing

Download all attachments as: .zip

Change History (15)

@aaroncampbell
8 years ago

MU plugin for testing

#1 @aaroncampbell
8 years ago

  • Keywords reporter-feedback added

I tested this and it's working for me. I made a quick MU plugin to test with (it tests it in an admin notice, so just put the plugin in the mu-plugins folder and load an admin page). Can you make sure you're testing this with no plugins enabled and a default theme?

#2 follow-up: @kraftbj
8 years ago

Thanks for the report! Noting that this format of shortcode did fail in 4.4, but was fixed in 4.4.1 ( #34939 , r36098 ).
Disregard; I misread the example.

Last edited 8 years ago by kraftbj (previous) (diff)

#3 in reply to: ↑ 2 ; follow-up: @aaroncampbell
8 years ago

Replying to kraftbj:

Thanks for the report! Noting that this format of shortcode did fail in 4.4, but was fixed in 4.4.1 ( #34939 , r36098 ).

I'm not sure that's related here. That was for shortcodes with unnamed attributes, like [shotcode=xyz]. This one didn't have any of those.

#4 in reply to: ↑ 3 @kraftbj
8 years ago

Replying to aaroncampbell:

I'm not sure that's related here. That was for shortcodes with unnamed attributes, like [shotcode=xyz]. This one didn't have any of those.

My mistake. I misread the example shortcode content_with_image image_position="left" as one lacking a space in there. Disregard.

#5 @dezio1900
8 years ago

I tried the mu-plugin, and shortcode works in admin area, as part of admin notice output.

But it appears that issue is somewhere in filters applied to the_content.

This is the content of the page I am using, which fails (text version) :

[content]

Safety is Glacier Raft Company’s number one priority. No exceptions, no question, no ifs, ands or buts about it. Keeping you and your family safe is our primary goal, and the decisions we make each and everyday are based on the importance of keeping this true.

Prioritizing safety doesn’t mean adventure is compromised. It means you can have the best possible day of white water rafting because you never have to question if safety is as important to us as it is to you.

[content_with_image image_position="left" image_id="198" content_margin_top="0" title="EXPERIENCED GUIDES" allow_content_below_image="no"]

All of our trips are led by professionals who have years of experience working as whitewater raft guides on the Kicking Horse River. They have rafted 100s (if not 1000s of trips), and their goal is to have a safe, clean run everyday.

They each have a valid British Columbia River Outfitters Association Guide Licence, Swift Water Rescue Technician Certificate, and Wilderness First Aid Certificate.

[/content_with_image]

[content_with_image image_position="right" image_id="1137" content_margin_top="0" title="CHECKING WATER LEVELS" allow_content_below_image="no"]

We check water levels every morning, and we have strict guidelines and cutoffs that dictate our course for the day. If water levels are above a specific cutoff point, we will not raft certain sections.

This happens commonly in June on the Kicking Horse River when the water is too high for us to run the lower canyon. This doesn’t mean you’re going to experience any less of an adventure, however. High water brings the biggest rapids and biggest hits, and the middle canyon at this time has the most whitewater we’ll see at any point throughout the summer.

[/content_with_image]

[content_with_image image_position="left" image_id="1138" content_margin_top="0" title="INTRO TALKS AND SAFETY BRIEFINGS" allow_content_below_image="no"]

Our guides go through very thorough intro talks and safety briefings before you get anywhere near the water. They’ll go over how to get ready, what to expect, and what to do in the event something does happen. While flips and swims are rare, they do occur, and we want you to be as prepared as possible just in case.

Our guides provide clear instructions and demonstrations, and they have you practice various commands before you get into any whitewater.  Once you’re in the raft everyone is working together as a team, and your guide will provide you with the skills and knowledge required to achieve this.

[/content_with_image]

[content_with_image image_position="right" image_id="1139" content_margin_top="0" title="MINIMUM AGE REQUIREMENTS" allow_content_below_image="no"]

Our minimum age, height and weight restrictions were also established with safety in mind.

Who has to stay and who gets to go is always left up to the discretion of our guides.  We know it can be tough when the whole family can’t continue on together, but the guides’ decisions are always made with your best interest at heart.  If they don’t feel it’s safe for someone to carry on it’s for a very good reason.

[/content_with_image]

[/content]

[testimonial bg_image_id="1340" signature="MichelleHughson, TripAdvisor" bg_color="0,0,0,0.3"]
<blockquote>Glacier's main focus was safety by far. They were very clear and explicit about all aspects of safety but made sure that everyone felt comfortable to ensure a great time. It was my first time white water rafting and no part of it made me nervous after all the instructions were given.</blockquote>
[/testimonial]
[content]
As required by all adventure activity providers, each guest of Glacier Raft Company will be required to read and sign a Release of Liability, Waiver of Claims and Assumption of Risks and Indemnity Agreement prior to their rafting trip.<span class="Apple-converted-space">  </span>To view this document, please <a title="Waiver" href="http://glacierraft.com/wp-content/uploads/2015/03/Waiver-GRC-GRA-2014-update-Vers.16-incl.-e-m-cnst-legal-size-final.pdf" target="_blank">click here.</a>
[/content]

All other shortcodes works, but "content_with_image" one fail, even when I have simple return string in shortcode PHP source.

As soon as I overwrite /wp-includes/shortcodes.php file with one from v4.3, it works. I also tried using default WP theme ( Twenty Fifteen - v1.4 ) and with all plugins disabled - same issue.

And when I manually write something like this:

[content_with_image image_id="100"]

Test...

[/content_with image]

Then it works.

@aaroncampbell
8 years ago

MU plugin for testing

#6 follow-up: @aaroncampbell
8 years ago

So the problem I see with the content that you pasted is that it's actually using nested shortcodes, which WordPress doesn't support by default. Basically, all your content_with_image shortcodes are contained within a content shortcode. In order to handle nested shortcodes like that,your content shortcode needs to call do_shortcode() on it's contents. In the updated MU test plugin, I added an example that you can see. The content shortcode does not run do_shortcode() on it's contents (thus outputting the raw text of the nested shortcode) and the content-do-shortcode shortcode DOES (thus outputting the processed shortcode). I copied the contents of the 4.3 version of wp-includes/shortcodes.php file over my existing one, and it didn't change the behavior of my tests at all.

#7 follow-up: @dezio1900
8 years ago

This topic describes the same issue I am having: https://wordpress.org/support/topic/shortcode-broken-with-wp-44-upgrade?replies=28

And this post is the actual answer to what is the bug:
"4.4 "broke" one of my shortcodes too. I tracked it down to the space character. Seems that when I originally copied and pasted the shortcode into my page, the space character following the shortcode (the delimiter space) was not ASCII 32. It was some other space. I fixed the problem by deleting the space following my shortcode name and reinserting the space with the spacebar. Saved the page and my shortcode started working again."

When I copy actual shortcode, and manually typed shortcode in Sublime Text, and set to show space charachter, I then can see the issue with first space after shortcode opening tag:
http://prntscr.com/a2cksu

So the dilema is how the shortcode parse changed from 4.3 to 4.4. How it successfully proccess that "strange space" char in 4.3 and fails in 4.4.

Client obviosly used 3rd party WYSIWYG, like Microsoft Word, so it appears thats causing the issue.

So this is definitely a bug, and support for that "strange space" char should be put back in shortcode parsing source, in order to support pasting from 3rd party WYSIWYG.

Version 0, edited 8 years ago by dezio1900 (next)

#8 in reply to: ↑ 7 @kraftbj
8 years ago

Replying to dezio1900:

And this post is the actual answer to what is the bug:
"4.4 "broke" one of my shortcodes too. I tracked it down to the space character. Seems that when I originally copied and pasted the shortcode into my page, the space character following the shortcode (the delimiter space) was not ASCII 32. It was some other space. I fixed the problem by deleting the space following my shortcode name and reinserting the space with the spacebar. Saved the page and my shortcode started working again."

When I copy actual shortcode, and manually typed shortcode in Sublime Text, and set to show space charachter, I then can see the issue with first space after shortcode opening tag:
http://prntscr.com/a2cksu

@otto42 addressed that in https://core.trac.wordpress.org/ticket/34939#comment:22 . Basically, it used to work because of a happy accident and didn't intentionally work. Need to decide the next step if we support it or fix it some other way.

#9 in reply to: ↑ 6 @dezio1900
8 years ago

kraftbj aaroncampbell What we should do? Is this going to be added to core? I see the other topic you sent, but it is closed.

And leaving this as not active means that our sites might break again after WP update.

#10 @dezio1900
8 years ago

Fixed by creating this content filter:

<?php
add_filter( 'the_content', function( $content ){
                
        return str_replace( "\xc2\xa0", " ", $content);
                
}, 1);

#11 @swissspidy
7 years ago

  • Keywords 2nd-opinion close added

The original issue was about nested shortcodes. After that, hidden characters (nbsp, etc.) came up, which doesn't seem to be a huge issue overall (first time I see it), so not sure if it's worth fixing. Anyway, it would be better off in a new ticket.

#12 @gitlost
7 years ago

Looks like it's now a duplicate of #35022 (which from puzzled personal experience is worth fixing!).

#13 @swissspidy
7 years ago

  • Keywords reporter-feedback 2nd-opinion close removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #35022.

Indeed, thanks for pointing this out!

Note: See TracTickets for help on using tickets.