*
* @since 2.5.0
*
- * @uses $shortcode_tags
+ * @global array $shortcode_tags
*
- * @param string $tag Shortcode tag to be searched in post content.
+ * @param string $tag Shortcode tag to be searched in post content.
* @param callable $func Hook to run when shortcode is found.
*/
function add_shortcode($tag, $func) {
global $shortcode_tags;
-
- if ( is_callable($func) )
- $shortcode_tags[$tag] = $func;
+ $shortcode_tags[ $tag ] = $func;
}
/**
*
* @since 2.5.0
*
- * @uses $shortcode_tags
+ * @global array $shortcode_tags
*
* @param string $tag Shortcode tag to remove hook for.
*/
*
* @since 2.5.0
*
- * @uses $shortcode_tags
+ * @global array $shortcode_tags
*/
function remove_all_shortcodes() {
global $shortcode_tags;
$pattern = get_shortcode_regex();
$content = preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content );
-
+
// Always restore square braces so we don't break things like <!--[if IE ]>
$content = unescape_invalid_shortcodes( $content );
-
+
return $content;
}
*
* @since 2.5.0
*
- * @uses $shortcode_tags
+ * @global array $shortcode_tags
*
* @return string The shortcode search regular expression
*/
*
* @since 2.5.0
* @access private
- * @uses $shortcode_tags
+ *
+ * @global array $shortcode_tags
*
* @param array $m Regular expression match array
- * @return mixed False on failure.
+ * @return string|false False on failure.
*/
function do_shortcode_tag( $m ) {
global $shortcode_tags;
$tag = $m[2];
$attr = shortcode_parse_atts( $m[3] );
+ if ( ! is_callable( $shortcode_tags[ $tag ] ) ) {
+ $message = sprintf( __( 'Attempting to parse a shortcode without a valid callback: %s' ), $tag );
+ _doing_it_wrong( __FUNCTION__, $message, '4.3.0' );
+ return $m[0];
+ }
+
if ( isset( $m[5] ) ) {
// enclosing tag - extra parameter
return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, $m[5], $tag ) . $m[6];
$trans = array( '[' => '[', ']' => ']' );
$content = strtr( $content, $trans );
$trans = array( '[' => '[', ']' => ']' );
-
+
$pattern = get_shortcode_regex();
$textarr = wp_html_split( $content );
$element = strtr( $element, $trans );
continue;
}
-
+
// Get element name
$front = array_shift( $attributes );
$back = array_pop( $attributes );
$matches = array();
preg_match('%[a-zA-Z0-9]+%', $front, $matches);
$elname = $matches[0];
-
+
// Look for shortcodes in each attribute separately.
foreach ( $attributes as &$attr ) {
$open = strpos( $attr, '[' );
if ( $count > 0 ) {
// Sanitize the shortcode output using KSES.
$new_attr = wp_kses_one_attr( $new_attr, $elname );
- if ( '' !== $new_attr ) {
+ if ( '' !== trim( $new_attr ) ) {
// The shortcode is safe to use now.
$attr = $new_attr;
}
}
}
$element = $front . implode( '', $attributes ) . $back;
-
+
// Now encode any remaining [ or ] chars.
$element = strtr( $element, $trans );
}
-
+
$content = implode( '', $textarr );
-
+
return $content;
}
// Clean up entire string, avoids re-parsing HTML.
$trans = array( '[' => '[', ']' => ']' );
$content = strtr( $content, $trans );
-
+
return $content;
}
*/
function shortcode_parse_atts($text) {
$atts = array();
- $pattern = '/(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';
+ $pattern = '/([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*\'([^\']*)\'(?:\s|$)|([\w-]+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';
$text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text);
if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) {
foreach ($match as $m) {
elseif (isset($m[8]))
$atts[] = stripcslashes($m[8]);
}
-
- // Reject any unclosed HTML elements
- foreach( $atts as &$value ) {
- if ( false !== strpos( $value, '<' ) ) {
- if ( 1 !== preg_match( '/^[^<]*+(?:<[^>]*+>[^<]*+)*+$/', $value ) ) {
- $value = '';
- }
- }
- }
} else {
$atts = ltrim($text);
}
*
* @since 2.5.0
*
- * @param array $pairs Entire list of supported attributes and their defaults.
- * @param array $atts User defined attributes in shortcode tag.
+ * @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
* @return array Combined and filtered attribute list.
*/
*
* @since 3.6.0
*
- * @param array $out The output array of shortcode attributes.
+ * @param array $out The output array of shortcode attributes.
* @param array $pairs The supported attributes and their defaults.
- * @param array $atts The user defined shortcode attributes.
+ * @param array $atts The user defined shortcode attributes.
*/
if ( $shortcode )
$out = apply_filters( "shortcode_atts_{$shortcode}", $out, $pairs, $atts );
*
* @since 2.5.0
*
- * @uses $shortcode_tags
+ * @global array $shortcode_tags
*
* @param string $content Content to remove shortcode tags.
* @return string Content without shortcode tags.
// Always restore square braces so we don't break things like <!--[if IE ]>
$content = unescape_invalid_shortcodes( $content );
-
+
return $content;
}
+/**
+ *
+ * @param array $m
+ * @return string|false
+ */
function strip_shortcode_tag( $m ) {
// allow [[foo]] syntax for escaping a tag
if ( $m[1] == '[' && $m[6] == ']' ) {