#12505 closed defect (bug) (fixed)
embed is not registered as a shortcode
Reported by: | MattyRob | Owned by: | Viper007Bond |
---|---|---|---|
Milestone: | 3.0 | Priority: | normal |
Severity: | normal | Version: | 2.9.2 |
Component: | Shortcodes | Keywords: | |
Focuses: | Cc: |
Description
The strip_shortcodes function used regex to strip short codes from post content however it leaves [embed] short codes behind.
This is apparently because the core code does not register embed as a shortcode.
Attachments (1)
Change History (12)
#2
in reply to:
↑ 1
@
15 years ago
It's a no-op, which is fine because embed is actually handled specially in embed.php
I mean media.php
#3
@
15 years ago
- Owner set to Viper007Bond
- Priority changed from high to normal
- Status changed from new to assigned
#4
@
15 years ago
You guys are incorrect. "embed" is registered as a shortcode, but only for a short amount of time. Look at WP_Embed::run_shortcode()
in /wp-includes/media.php
. It is a the_content
filter that hooks in pre-wpautop()
that runs one specific shortcode.
http://www.viper007bond.com/2009/11/22/wordpress-code-earlier-shortcodes/
The only solution I can think of is to register the tag to a dummy callback (as described by belg4mit) but then substitute it out for the real callback when we actually go to render it. A bit messy, but it should work.
#5
follow-up:
↓ 6
@
15 years ago
Interesting and puzzling. Why register the shortcode and then de-register it?!?
Also, if I amend your code and register 'embed' but add it to the array of tags and then strip them before restoring the original array would that 'fix' the strip_shortcodes function?
#6
in reply to:
↑ 5
@
15 years ago
Replying to MattyRob:
Interesting and puzzling. Why register the shortcode and then de-register it?!?
As I said, shortcodes normally run at 11, after wpautop()
at 10. It works much better if the [embed]
shortcode is processed pre-wpautop()
.
Also, if I amend your code and register 'embed' but add it to the array of tags and then strip them before restoring the original array would that 'fix' the strip_shortcodes function?
Not sure what you mean, but I'll be personally writing a patch to fix this very soon.
#7
follow-up:
↓ 8
@
15 years ago
Thanks for the clarification - so is this (embed not being in the short codes list) needed because wpautop() somehow messes up the embed shortcode?
My 'fix' is something like this:
global $shortcode_tags; // Backup current registered shortcodes $orig_shortcode_tags = $shortcode_tags; // Add 'embed' then strip all shortcodes add_shortcode( 'embed', create_function('', '') ); $content = strip_shortcodes( $content ); // Put the original shortcodes back $shortcode_tags = $orig_shortcode_tags; return $content;
I guess WordPress could introduce a second strip_shortcodes function or perhaps a 'force' parameter to ensure that embed is stripped out. Looking forwar to you fix - then I can revert mine :-)
#8
in reply to:
↑ 7
@
15 years ago
Replying to MattyRob:
Thanks for the clarification - so is this (embed not being in the short codes list) needed because wpautop() somehow messes up the embed shortcode?
It has the potential to, yes, but more importantly we want the video wrapped in paragraph tags so it's not jammed up against the previous and next paragraphs. We can't just manually wrap it as we have no idea what the result will be, where the shortcode was used, etc.
#9
@
15 years ago
Sorry, I was misread belg4mit's comment. They were correct and deserve credit for this patch.
A work around is to add the following to functions.php
It's a no-op, which is fine because embed is actually handled specially in embed.php
(not shortcode.php). It's only purpose is to make an entry with the key embed into
the global $shortcode_tags which is what is used to strip_shortcodes.
This is especially handy if you use something like Subscribe2.