X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/baca9ce86a38dc54c4574890ee2d352fd81f78b2..61343b82c4f0da4c68e4c6373daafff4a81efdd1:/wp-includes/shortcodes.php diff --git a/wp-includes/shortcodes.php b/wp-includes/shortcodes.php index 2dfc2774..a4095949 100644 --- a/wp-includes/shortcodes.php +++ b/wp-includes/shortcodes.php @@ -127,6 +127,43 @@ function remove_all_shortcodes() { $shortcode_tags = array(); } +/** + * Whether a registered shortcode exists named $tag + * + * @since 3.6.0 + * + * @global array $shortcode_tags + * @param string $tag + * @return boolean + */ +function shortcode_exists( $tag ) { + global $shortcode_tags; + return array_key_exists( $tag, $shortcode_tags ); +} + +/** + * Whether the passed content contains the specified shortcode + * + * @since 3.6.0 + * + * @global array $shortcode_tags + * @param string $tag + * @return boolean + */ +function has_shortcode( $content, $tag ) { + if ( shortcode_exists( $tag ) ) { + preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ); + if ( empty( $matches ) ) + return false; + + foreach ( $matches as $shortcode ) { + if ( $tag === $shortcode[2] ) + return true; + } + } + return false; +} + /** * Search content for shortcodes and filter shortcodes through their hooks. * @@ -289,9 +326,10 @@ function shortcode_parse_atts($text) { * * @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. */ -function shortcode_atts($pairs, $atts) { +function shortcode_atts( $pairs, $atts, $shortcode = '' ) { $atts = (array)$atts; $out = array(); foreach($pairs as $name => $default) { @@ -300,6 +338,10 @@ function shortcode_atts($pairs, $atts) { else $out[$name] = $default; } + + if ( $shortcode ) + $out = apply_filters( "shortcode_atts_{$shortcode}", $out, $pairs, $atts ); + return $out; }