Opened 10 years ago
Closed 10 years ago
#32445 closed enhancement (fixed)
`is_callable()` should be checked in `do_shortcode_tag()`, not `add_shortcode()`
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.3 | Priority: | normal |
Severity: | normal | Version: | 2.6 |
Component: | Shortcodes | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
Actions and filters can be registered before their callbacks actually exist. The same should be true for shortcodes. This is a followup of #30947 - would be good to be able to add all shortcodes in default-filters.php
Attachments (2)
Change History (9)
#2
@
10 years ago
- Keywords needs-refresh added
The patch seems to work, passes all the tests, etc, but I'm a little leery of moving all our default shortcodes into default-filters.php. It all seems to work for core, but I'm convinced it won't cause issues elsewhere. Can we limit this patch to just the is_callable fix?
#3
@
10 years ago
- Keywords needs-refresh removed
Yeah, moving add_shortcode()
calls to default-filters.php will break things in weird situations, like including a few random files outside of WordPress. I'm not saying we should ever support that (and I often argue, such as in the SHORTINIT
situations, that we should not), but in this case, the only functions called in default-filters.php are add_action()
and add_filter()
(and is_admin()
). It should stay that way.
I'd agree with moving them out of here, but it should probably go to some kind of shortcodes_init()
like widgets and other things. Moving them too late could break plugins that currently remove them pretty early, however. Kind of stuck here.
I do like the callback change here, though.
(Random thought, if anyone wants to have some fun, we should rewrite the API to use hooks under the hood, and ditch $shortcode_tags
. And then break everyone reaching directly into $shortcode_tags
.)
#4
in reply to:
↑ 1
@
10 years ago
- Keywords commit added
32445.2.diff is wonderboymusic's 32445.diff without the moving of the add_shortcode()
calls. I think this fixes the actual problem without the extra code churn.
Another piece here - if you register a shortcode now without a valid callback, you get no notice in the logs and nothing happens to your shortcode (it isn't parsed).
32445.diff is all of the code that is required to make shortcode registration possible in
default-filters.php
. The only major diff is having to loadshortcodes.php
beforedefault-filters.php
in the bootstrap.In my patch, when a shortcode is being parsed and doesn't have a valid callback, a
_doing_it_wrong()
is fired._doing_it_wrong()
can't be called onadd_shortcode()
indefault-filters.php
because i10n is not loaded.