Shortcode Security Suggestions
Events Manager shortcodes such as [events_list] accept a custom format: a piece of HTML with placeholders that is repeated for each event. This page explains how to supply that format safely, why a format written years ago may now appear on your page as raw HTML, and the settings that bring the old behavior back while you fix your content.
It matters to you if you use shortcodes with your own formats. If you only use shortcodes with attributes such as limit or category, nothing here affects you.
What changed in 6.4.8
Before version 6.4.8, Events Manager decoded HTML entities in every format given to a shortcode. That covered the content between the tags, as in [events_list]content[/events_list], and the format, format_header and format_footer attributes.
Decoding made it possible for anyone who could publish content to pass harmful HTML through a shortcode in a form that WordPress's own filtering could not see. The Wordfence security team reported this, and 6.4.8 stopped the decoding.
The side effect: a format that was saved as entity-encoded text now prints as text. If your page contains this:
[events_list]<p>#_EVENTNAME</p>[/events_list]
then visitors see the tags themselves:
<p>Harbor Lights Jazz Night</p><p>Sunrise Beach Yoga</p>
This usually happens when a format was typed or pasted into a visual editor. The editor shows <p> on screen, but stores it as <p>.
Write formats the safe way
Put the format between the shortcode tags, and enter it as real HTML:
[events_list limit="5"]
<p>#_EVENTLINK, #_EVENTDATES</p>
[/events_list]
Where you type it decides whether it is stored as HTML:
- In the block editor, use a Shortcode block or a Custom HTML block. Don't type formats into a Paragraph block.
- In the classic editor, switch to the Text tab before typing or pasting the shortcode.
A quick test: if you can see HTML tags in an editor view where other text appears bold or styled, the tags are stored as text and will be shown as text.
Entered this way, your HTML is filtered by WordPress when the post is saved, according to what the author is allowed to use, and Events Manager outputs it unchanged.
Text that used to go in format_header and format_footer belongs before and after the shortcode:
<ul>
[events_list limit="5"]<li>#_EVENTLINK</li>[/events_list]
</ul>
This short video shows the difference in the classic editor, the Shortcode block and the Custom HTML block:
Transition settings
If an update left raw HTML on your pages and you can't fix every page at once, four settings restore the earlier behavior. They are in Events then Settings then General then Admin Tools (Advanced), under Shortcode HTML Entity Decoding. On a multisite network they are in the network admin, under Events Manager then Admin Tools (Advanced).
Four switches control decoding and the format attributes.
| Setting | What it does | New installs |
|---|---|---|
| Decode shortcode content? | Decodes HTML entities in the content between shortcode tags, so <p> becomes a real paragraph again. | No |
| Sanitize shortcode content? | Passes decoded content through WordPress's wp_kses() filter, which removes anything outside the HTML allowed in posts. Only applies when the setting above is Yes. Leave it on. | Yes |
| Allow format shortcode parameters? | Lets shortcodes use the format, format_header and format_footer attributes. When No, those attributes are ignored and only the content between the tags is used as the format. | No |
| Decode shortcode format parameters? | Decodes HTML entities in those three attributes. Only applies when the setting above is Yes. | No |
Sites that were already running Events Manager when these settings arrived had the format attributes and their decoding left on, so existing pages kept working. Sites updated from a version before 6.4.8 also had content decoding left on.
Two things are always true, whatever you choose:
- Formats given through the three attributes are filtered with
wp_kses()every time the page is displayed. - With Decode shortcode content? set to No, a format between the tags is output exactly as it was saved.
The risk in leaving them on
The settings screen marks these options in red as intended for transition. With decoding on, entity-encoded HTML reaches the page after WordPress has already checked the post, so the only protection left is the sanitizing step. That matters most when people you don't fully trust can publish content: sites with many authors, community sites with event submissions, and multisite networks, where the administrators of individual sites are still submitting content to your network.
With one or two trusted editors the risk is low. It is still worth moving your formats over, since decoding would also help anyone who managed to inject content into your site by another route.
Sanitizing has a cost
wp_kses() is designed for use when content is saved, not each time it is shown. Running it on every page view adds a little work for the server, which a busy site may notice. Formats written the safe way skip it altogether.
Move your content over
-
Turn on Decode shortcode content?, and Allow format shortcode parameters? if you use the format attributes, so the site looks right while you work.
-
Edit each page or post that has a shortcode with a format. Copy the HTML while it displays correctly in the visual view, then switch to the Text tab (or a Shortcode or Custom HTML block) and paste it over the encoded version, between the shortcode tags.
-
Move anything in
format_headerandformat_footerto before and after the shortcode, and move aformatattribute's value between the tags. -
Turn the settings off again and check the pages.
Keep the old behavior with code
The transition settings may be removed in a future version. If you need format attributes and entity-encoded formats for the long term, this filter re-applies them. It still sanitizes the result.
function my_em_legacy_shortcode_formats( $args, $format, $supplied_args = array() ) {
global $allowedposttags;
foreach ( array( 'format', 'format_header', 'format_footer' ) as $key ) {
// put back an attribute that was removed, unless a format was given between the tags
if ( ! empty( $supplied_args[ $key ] ) && ! ( $key === 'format' && ! empty( $format ) ) ) {
$args[ $key ] = $supplied_args[ $key ];
}
if ( ! empty( $args[ $key ] ) ) {
$args[ $key ] = wp_kses( html_entity_decode( $args[ $key ] ), $allowedposttags );
}
}
return $args;
}
add_filter( 'em_clean_shortcode_args', 'my_em_legacy_shortcode_formats', 10, 3 );