[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> shortcodes.php (summary)

WordPress API for creating bbcode-like tags or what WordPress calls "shortcodes". The tag and attribute parsing or regular expression code is based on the Textpattern tag parser. A few examples are below:

File Size: 764 lines (24 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 18 functions

  add_shortcode()
  remove_shortcode()
  remove_all_shortcodes()
  shortcode_exists()
  has_shortcode()
  get_shortcode_tags_in_content()
  apply_shortcodes()
  do_shortcode()
  _filter_do_shortcode_context()
  get_shortcode_regex()
  do_shortcode_tag()
  do_shortcodes_in_html_tags()
  unescape_invalid_shortcodes()
  get_shortcode_atts_regex()
  shortcode_parse_atts()
  shortcode_atts()
  strip_shortcodes()
  strip_shortcode_tag()

Functions
Functions that are not part of a class:

add_shortcode( $tag, $callback )   X-Ref
Adds a new shortcode.

Care should be taken through prefixing or other means to ensure that the
shortcode tag being added is unique and will not conflict with other,
already-added shortcode tags. In the event of a duplicated tag, the tag
loaded last will take precedence.

param: string   $tag      Shortcode tag to be searched in post content.
param: callable $callback The callback function to run when the shortcode is found.

remove_shortcode( $tag )   X-Ref
Removes hook for shortcode.

param: string $tag Shortcode tag to remove hook for.

remove_all_shortcodes()   X-Ref
Clears all shortcodes.

This function clears all of the shortcode tags by replacing the shortcodes global with
an empty array. This is actually an efficient method for removing all shortcodes.


shortcode_exists( $tag )   X-Ref
Determines whether a registered shortcode exists named $tag.

return: bool Whether the given shortcode exists.
param: string $tag Shortcode tag to check.

has_shortcode( $content, $tag )   X-Ref
Determines whether the passed content contains the specified shortcode.

return: bool Whether the passed content contains the given shortcode.
param: string $content Content to search for shortcodes.
param: string $tag     Shortcode tag to check.

get_shortcode_tags_in_content( $content )   X-Ref
Returns a list of registered shortcode names found in the given content.

Example usage:

get_shortcode_tags_in_content( '[audio src="file.mp3"][/audio] [foo] [gallery ids="1,2,3"]' );
// array( 'audio', 'gallery' )

return: string[] An array of registered shortcode names found in the content.
param: string $content The content to check.

apply_shortcodes( $content, $ignore_html = false )   X-Ref
Searches content for shortcodes and filter shortcodes through their hooks.

This function is an alias for do_shortcode().

return: string Content with shortcodes filtered out.
param: string $content     Content to search for shortcodes.
param: bool   $ignore_html When true, shortcodes inside HTML elements will be skipped.

do_shortcode( $content, $ignore_html = false )   X-Ref
Searches content for shortcodes and filter shortcodes through their hooks.

If there are no shortcode tags defined, then the content will be returned
without any filtering. This might cause issues when plugins are disabled but
the shortcode will still show up in the post or content.

return: string Content with shortcodes filtered out.
param: string $content     Content to search for shortcodes.
param: bool   $ignore_html When true, shortcodes inside HTML elements will be skipped.

_filter_do_shortcode_context()   X-Ref
Filter the `wp_get_attachment_image_context` hook during shortcode rendering.

When wp_get_attachment_image() is called during shortcode rendering, we need to make clear
that the context is a shortcode and not part of the theme's template rendering logic.

return: string The filtered context value for wp_get_attachment_images when doing shortcodes.

get_shortcode_regex( $tagnames = null )   X-Ref
Retrieves the shortcode regular expression for searching.

The regular expression combines the shortcode tags in the regular expression
in a regex class.

The regular expression contains 6 different sub matches to help with parsing.

1 - An extra [ to allow for escaping shortcodes with double [[]]
2 - The shortcode name
3 - The shortcode argument list
4 - The self closing /
5 - The content of a shortcode when it wraps some content.
6 - An extra ] to allow for escaping shortcodes with double [[]]

return: string The shortcode search regular expression
param: array $tagnames Optional. List of shortcodes to find. Defaults to all registered shortcodes.

do_shortcode_tag( $m )   X-Ref
Regular Expression callable for do_shortcode() for calling shortcode hook.

return: string Shortcode output.
param: array $m {

do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames )   X-Ref
Searches only inside HTML elements for shortcodes and process them.

Any [ or ] characters remaining inside elements will be HTML encoded
to prevent interference with shortcodes that are outside the elements.
Assumes $content processed by KSES already.  Users with unfiltered_html
capability may get unexpected output if angle braces are nested in tags.

return: string Content with shortcodes filtered out.
param: string $content     Content to search for shortcodes.
param: bool   $ignore_html When true, all square braces inside elements will be encoded.
param: array  $tagnames    List of shortcodes to find.

unescape_invalid_shortcodes( $content )   X-Ref
Removes placeholders added by do_shortcodes_in_html_tags().

return: string Content with placeholders removed.
param: string $content Content to search for placeholders.

get_shortcode_atts_regex()   X-Ref
Retrieves the shortcode attributes regex.

return: string The shortcode attribute regular expression.

shortcode_parse_atts( $text )   X-Ref
Retrieves all attributes from the shortcodes tag.

The attributes list has the attribute name as the key and the value of the
attribute as the value in the key/value pair. This allows for easier
retrieval of the attributes, since all attributes have to be known.

return: array Array of attribute values keyed by attribute name.
param: string $text Shortcode arguments list.

shortcode_atts( $pairs, $atts, $shortcode = '' )   X-Ref
Combines user attributes with known attributes and fill in defaults when needed.

The pairs should be considered to be all of the attributes which are
supported by the caller and given as a list. The returned attributes will
only contain the attributes in the $pairs list.

If the $atts list has unsupported attributes, then they will be ignored and
removed from the final returned list.

return: array Combined and filtered attribute list.
param: array  $pairs     Entire list of supported attributes and their defaults.
param: array  $atts      User defined attributes in shortcode tag.
param: string $shortcode Optional. The name of the shortcode, provided for context to enable filtering

strip_shortcodes( $content )   X-Ref
Removes all shortcode tags from the given content.

return: string Content without shortcode tags.
param: string $content Content to remove shortcode tags.

strip_shortcode_tag( $m )   X-Ref
Strips a shortcode tag based on RegEx matches against post content.

return: string|false The content stripped of the tag, otherwise false.
param: array $m RegEx matches against post content.



Generated : Sat Dec 21 08:20:01 2024 Cross-referenced by PHPXref