]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/shortcodes.php
WordPress 3.8.3
[autoinstalls/wordpress.git] / wp-includes / shortcodes.php
index 1b860d2766df8cca052a2c816279be6cd20af7d3..dafb3a14051b975357154390f8e689265ce4523a 100644 (file)
@@ -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.
  *
@@ -177,11 +214,12 @@ function get_shortcode_regex() {
        $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
 
        // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag()
+       // Also, see shortcode_unautop() and shortcode.js.
        return
                  '\\['                              // Opening bracket
                . '(\\[?)'                           // 1: Optional second opening bracket for escaping shortcodes: [[tag]]
                . "($tagregexp)"                     // 2: Shortcode name
-               . '\\b'                              // Word boundary
+               . '(?![\\w-])'                       // Not followed by word character or hyphen
                . '('                                // 3: Unroll the loop: Inside the opening shortcode tag
                .     '[^\\]\\/]*'                   // Not a closing bracket or forward slash
                .     '(?:'
@@ -288,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) {
@@ -299,6 +338,21 @@ function shortcode_atts($pairs, $atts) {
                else
                        $out[$name] = $default;
        }
+       /**
+        * Filter a shortcode's default attributes.
+        *
+        * If the third parameter of the shortcode_atts() function is present then this filter is available.
+        * The third parameter, $shortcode, is the name of the shortcode.
+        *
+        * @since 3.6.0
+        *
+        * @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.
+        */
+       if ( $shortcode )
+               $out = apply_filters( "shortcode_atts_{$shortcode}", $out, $pairs, $atts );
+
        return $out;
 }