#27278 closed defect (bug) (fixed)
Clarifying add_theme_support() inline docs for 'html5'
Reported by: | jond3r | Owned by: | DrewAPicture |
---|---|---|---|
Milestone: | 3.9 | Priority: | normal |
Severity: | normal | Version: | 3.9 |
Component: | Themes | Keywords: | has-patch |
Focuses: | docs | Cc: |
Description
In #26697 was introduced support for HTML5 markup in image galleries. To enable this you would have to write:
add_theme_support( 'html5', array( 'gallery' ) );
Previously there were just three so-called 'types' of HTML5 support in core: 'comment-list', 'comment-form', 'search-form'.
So now there is one more: 'gallery'!
This has pinpointed a weakness (or asymmetry if you like) in the current API for theme support. Though discouraged (ticket:26697#comment:12), it is currently possible and legitimate to use:
add_theme_support( 'html5' );
which adds support for the three types 'comment-list', 'comment-form' and 'search-form', but not the new type 'gallery'!
Thus, as the code stands today 'gallery' is treated as a second-class citizen, which it does not deserve!
Another manifestation of the current asymmetry of the API is that remove_theme_support( 'html5' )
removes all previously added types, but add_theme_support( 'html5' )
only adds back three of them.
To add some sanity back to the theme support API, three possible roads are outlined:
- Keep the current code as is, for preserved backwards compatibility, but add some comment to the code and an additional assertion for clarity to the theme-support test. This is provided in the attached patch no. 1.
- Add 'gallery' to the default list of types for preserved symmetry but broken back-compat, with some additional test assertion. This is patch no. 2.
- Remove the possibility to use
add_theme_support( 'html5' )
altogether, which breaks back-compat this time, but is future proof as other types are added. It also restores symmetry of the API, albeit in another form. Adjust the unit tests accordingly. This is patch no. 3.
I do not have very strong feelings about which road is better. No. 1 is safest, but does not provide much improvement. Patch no. 2 was rejected in ticket:26697#comment:12, and will realistically not be accepted as it is not future proof and breaks back-compat in a silent way: gallery styling might stop working for themes or plugins using add_theme_support( 'html5' )
. Patch no. 3 is 100% future-proof, but usage of add_theme_support( 'html5' )
will trigger a doing-it-wrong error. It is somewhat 'boring' though, as something is taken away, and a longer api-call must be made to achieve the same thing as before.
Much of the current behavior was added in #24932.
Attachments (8)
Change History (22)
#1
@
11 years ago
- Keywords has-patch added
- Summary changed from More sanity for add_theme_support( 'html5' ) to More sanity to add_theme_support( 'html5' )
#2
@
11 years ago
#3
@
11 years ago
Option 1 seems sensible to me. It doesn't relegate gallery
to any non-preferred status, it's just a fallback for people who implemented html5
support before gallery
support existed. If all the documentation recommends being explicit with what elements you want on, use of html5
without explicit support will go way down.
This preserves backward compat without breaking sites.
Removing the ability to use html5
by itself isn't "future proof as other types are added" any more than option 1 is. All it does is forces unnecessary failures with the only real benefit being the removal of some code.
As far as I'm concerned, this doesn't even warrant a _doing_it_wrong
trigger. Themes (for the most part) don't exactly have a way of pushing updates out to users.
#6
@
11 years ago
The general message here seems to be: "Change as little as possible". Still I think it would be valuable to have some comment in the code to indicate what is considered as deprecated usage (some devs might not read the codex).
The attached .6 patch is essentially a modified version of .1 that tries to better adhere to the documentation standards (replacing 'void' with 'mixed' in the @return line). The unit tests are also not touched.
Edit: I raised the issue of using void
in mixed type @return
here: comment:19:ticket:27098
#7
follow-up:
↓ 8
@
11 years ago
I don't really see the benefit of adding a @return value here.
This function doesn't have a consistent return value (nor do I think it should), so why would anyone check it? The _doing_it_wrong()
message is pretty clear.
Let's just add a comment from 27278.6.diff.
#8
in reply to:
↑ 7
@
11 years ago
Replying to SergeyBiryukov:
I don't really see the benefit of adding a @return value here.
I agree to some extent. I think it is best to have a consistent return type, bool e.g., but that should have been thought of at design time.
#9
@
11 years ago
Patch .7 restores the use of @return void|bool
as I think this is accepted usage of void
, based on for example [27575].
The @return line can be skipped if deemed unnecessary (though I think it should be added).
#10
@
11 years ago
- Summary changed from More sanity to add_theme_support( 'html5' ) to Clarifying comment in add_theme_support() for 'html5'
Changed the title to more accurately describe the current patch.
#11
@
11 years ago
- Focuses docs added
- Summary changed from Clarifying comment in add_theme_support() for 'html5' to Clarifying add_theme_support() inline docs for 'html5'
That list is just for backwards compatibility, new items should not be added there.
27278.4.diff adds a
_doing_it_wrong()
call and a "Back compat" comment, per comment:12:ticket:26697. I think that's all we need here. We didn't do that originally, as the consensus in comment:12:ticket:24932 was that_doing_it_wrong()
was not necessary until we actually had a new markup in some other function. Now that we've added it togallery_shortcode()
, let's do this.