WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#22919 closed defect (bug) (fixed)

Gallery shortcode columns attribute present, even when default

Reported by: kovshenin Owned by: koopersmith
Milestone: 3.5.1 Priority: normal
Severity: normal Version: 3.5
Component: Media Keywords: has-patch commit
Focuses: Cc:

Description

I love new media! Anyway, the default columns value is 3, so here's a scenario:

  1. Add a new post
  2. Hit Add Media, Create Gallery, select a few images and hit insert. Switch to Text mode. You'll see the gallery shortcode has been inserted with only the ids attribute, which is expected.
  3. Make sure you're in Visual mode. Select the Gallery and hit the little Edit Gallery button, set Columns to 5, hit Update Gallery and switch to Text mode. You'll see that the gallery shortcode now also has columns="5" which is expected.
  4. Edit the gallery again and set Columns back to 3. Hit Update and switch to Text. You'll see the shortcode has columns="3" but expected to see no columns attribute since 3 is the default.

The same behavior happens on the link attribute. The "correct" behavior happens on the orderby="rand" attribute, which is removed from the shortcode when set to the default (off) state.

Attachments (1)

media-editor.js.diff (409 bytes) - added by adamsilverstein 5 years ago.

Download all attachments as: .zip

Change History (10)

#1 @nacin
5 years ago

  • Milestone changed from Awaiting Review to 3.5.1

#2 @adamsilverstein
5 years ago

  • Cc ADAMSILVERSTEIN@… added
  • Keywords has-patch added

i could not reproduce the error with the link attribute.

changed default value to string from int, correcting failed comparison (on line 251)

#3 follow-up: @nacin
5 years ago

  • Keywords commit added
  • Owner set to koopersmith
  • Status changed from new to reviewing

Looks good.

#4 in reply to: ↑ 3 @adamsilverstein
5 years ago

Replying to nacin:

Looks good.

Great! My first patch was accepted...

That was fun! I'll be back :)

#5 @aaroncampbell
5 years ago

Just thinking out loud here: What if the default changes in the future? If a user specifically chooses "3" maybe the parameter should actually stay?

#6 @adamsilverstein
5 years ago

i would probably agree, but i think the idea is to insert a shortcode that contains only information that's required. i agree this ties the defaults down, changing them would break any shortcodes without a hard coded value.

by extension, i think your logic would suggest inserting the default values for all options when inserting the gallery in the first place, which would be pretty excessive.

#7 @koopersmith
5 years ago

In 23247:

Don't include the default columns="3" in a gallery shortcode.

Shortcode attributes are strings; fix a variable type error in wp.media.gallery defaults.
props adamsilverstein.

see #22919.

#8 follow-up: @nacin
5 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 23248:

Don't include the default columns="3" in a gallery shortcode.

Shortcode attributes are strings; fix a variable type error in wp.media.gallery defaults.

Merges [23247] to the 3.5 branch.

props adamsilverstein.
fixes #22919.

#9 in reply to: ↑ 8 @adamsilverstein
5 years ago

:) grin

Replying to nacin:

In 23248:

Don't include the default columns="3" in a gallery shortcode.

Shortcode attributes are strings; fix a variable type error in wp.media.gallery defaults.

Merges [23247] to the 3.5 branch.

props adamsilverstein.
fixes #22919.

Note: See TracTickets for help on using tickets.