wp/wp-includes/shortcodes.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
--- a/wp/wp-includes/shortcodes.php	Mon Jun 08 16:11:51 2015 +0000
+++ b/wp/wp-includes/shortcodes.php	Tue Jun 09 03:35:32 2015 +0200
@@ -21,21 +21,20 @@
  *
  * To apply shortcode tags to content:
  *
- * <code>
- * $out = do_shortcode($content);
- * </code>
+ *     $out = do_shortcode( $content );
  *
- * @link http://codex.wordpress.org/Shortcode_API
+ * @link https://codex.wordpress.org/Shortcode_API
  *
  * @package WordPress
  * @subpackage Shortcodes
- * @since 2.5
+ * @since 2.5.0
  */
 
 /**
  * Container for storing shortcode tags and their hook to call for the shortcode
  *
- * @since 2.5
+ * @since 2.5.0
+ *
  * @name $shortcode_tags
  * @var array
  * @global array $shortcode_tags
@@ -51,40 +50,37 @@
  *
  * Simplest example of a shortcode tag using the API:
  *
- * <code>
- * // [footag foo="bar"]
- * function footag_func($atts) {
- * 	return "foo = {$atts[foo]}";
- * }
- * add_shortcode('footag', 'footag_func');
- * </code>
+ *     // [footag foo="bar"]
+ *     function footag_func( $atts ) {
+ *         return "foo = {
+ *             $atts[foo]
+ *         }";
+ *     }
+ *     add_shortcode( 'footag', 'footag_func' );
  *
  * Example with nice attribute defaults:
  *
- * <code>
- * // [bartag foo="bar"]
- * function bartag_func($atts) {
- * 	extract(shortcode_atts(array(
- * 		'foo' => 'no foo',
- * 		'baz' => 'default baz',
- * 	), $atts));
+ *     // [bartag foo="bar"]
+ *     function bartag_func( $atts ) {
+ *         $args = shortcode_atts( array(
+ *             'foo' => 'no foo',
+ *             'baz' => 'default baz',
+ *         ), $atts );
  *
- * 	return "foo = {$foo}";
- * }
- * add_shortcode('bartag', 'bartag_func');
- * </code>
+ *         return "foo = {$args['foo']}";
+ *     }
+ *     add_shortcode( 'bartag', 'bartag_func' );
  *
  * Example with enclosed content:
  *
- * <code>
- * // [baztag]content[/baztag]
- * function baztag_func($atts, $content='') {
- * 	return "content = $content";
- * }
- * add_shortcode('baztag', 'baztag_func');
- * </code>
+ *     // [baztag]content[/baztag]
+ *     function baztag_func( $atts, $content = '' ) {
+ *         return "content = $content";
+ *     }
+ *     add_shortcode( 'baztag', 'baztag_func' );
  *
- * @since 2.5
+ * @since 2.5.0
+ *
  * @uses $shortcode_tags
  *
  * @param string $tag Shortcode tag to be searched in post content.
@@ -100,10 +96,11 @@
 /**
  * Removes hook for shortcode.
  *
- * @since 2.5
+ * @since 2.5.0
+ *
  * @uses $shortcode_tags
  *
- * @param string $tag shortcode tag to remove hook for.
+ * @param string $tag Shortcode tag to remove hook for.
  */
 function remove_shortcode($tag) {
 	global $shortcode_tags;
@@ -118,7 +115,8 @@
  * shortcodes global by a empty array. This is actually a very efficient method
  * for removing all shortcodes.
  *
- * @since 2.5
+ * @since 2.5.0
+ *
  * @uses $shortcode_tags
  */
 function remove_all_shortcodes() {
@@ -132,9 +130,10 @@
  *
  * @since 3.6.0
  *
- * @global array $shortcode_tags
- * @param string $tag
- * @return boolean
+ * @global array $shortcode_tags List of shortcode tags and their callback hooks.
+ *
+ * @param string $tag Shortcode tag to check.
+ * @return bool Whether the given shortcode exists.
  */
 function shortcode_exists( $tag ) {
 	global $shortcode_tags;
@@ -147,18 +146,27 @@
  * @since 3.6.0
  *
  * @global array $shortcode_tags
- * @param string $tag
- * @return boolean
+ *
+ * @param string $content Content to search for shortcodes.
+ * @param string $tag     Shortcode tag to check.
+ * @return bool Whether the passed content contains the given shortcode.
  */
 function has_shortcode( $content, $tag ) {
+	if ( false === strpos( $content, '[' ) ) {
+		return false;
+	}
+
 	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] )
+			if ( $tag === $shortcode[2] ) {
 				return true;
+			} elseif ( ! empty( $shortcode[5] ) && has_shortcode( $shortcode[5], $tag ) ) {
+				return true;
+			}
 		}
 	}
 	return false;
@@ -171,16 +179,20 @@
  * without any filtering. This might cause issues when plugins are disabled but
  * the shortcode will still show up in the post or content.
  *
- * @since 2.5
- * @uses $shortcode_tags
- * @uses get_shortcode_regex() Gets the search pattern for searching shortcodes.
+ * @since 2.5.0
  *
- * @param string $content Content to search for shortcodes
+ * @global array $shortcode_tags List of shortcode tags and their callback hooks.
+ *
+ * @param string $content Content to search for shortcodes.
  * @return string Content with shortcodes filtered out.
  */
 function do_shortcode($content) {
 	global $shortcode_tags;
 
+	if ( false === strpos( $content, '[' ) ) {
+		return $content;
+	}
+
 	if (empty($shortcode_tags) || !is_array($shortcode_tags))
 		return $content;
 
@@ -203,7 +215,8 @@
  * 5 - The content of a shortcode when it wraps some content.
  * 6 - An extra ] to allow for escaping shortcodes with double [[]]
  *
- * @since 2.5
+ * @since 2.5.0
+ *
  * @uses $shortcode_tags
  *
  * @return string The shortcode search regular expression
@@ -250,7 +263,7 @@
  * Regular Expression callable for do_shortcode() for calling shortcode hook.
  * @see get_shortcode_regex for details of the match array contents.
  *
- * @since 2.5
+ * @since 2.5.0
  * @access private
  * @uses $shortcode_tags
  *
@@ -284,7 +297,7 @@
  * attribute as the value in the key/value pair. This allows for easier
  * retrieval of the attributes, since all attributes have to be known.
  *
- * @since 2.5
+ * @since 2.5.0
  *
  * @param string $text
  * @return array List of attributes and their value.
@@ -301,7 +314,7 @@
 				$atts[strtolower($m[3])] = stripcslashes($m[4]);
 			elseif (!empty($m[5]))
 				$atts[strtolower($m[5])] = stripcslashes($m[6]);
-			elseif (isset($m[7]) and strlen($m[7]))
+			elseif (isset($m[7]) && strlen($m[7]))
 				$atts[] = stripcslashes($m[7]);
 			elseif (isset($m[8]))
 				$atts[] = stripcslashes($m[8]);
@@ -322,7 +335,7 @@
  * If the $atts list has unsupported attributes, then they will be ignored and
  * removed from the final returned list.
  *
- * @since 2.5
+ * @since 2.5.0
  *
  * @param array $pairs Entire list of supported attributes and their defaults.
  * @param array $atts User defined attributes in shortcode tag.
@@ -359,7 +372,8 @@
 /**
  * Remove all shortcode tags from the given content.
  *
- * @since 2.5
+ * @since 2.5.0
+ *
  * @uses $shortcode_tags
  *
  * @param string $content Content to remove shortcode tags.
@@ -368,6 +382,10 @@
 function strip_shortcodes( $content ) {
 	global $shortcode_tags;
 
+	if ( false === strpos( $content, '[' ) ) {
+		return $content;
+	}
+
 	if (empty($shortcode_tags) || !is_array($shortcode_tags))
 		return $content;
 
@@ -384,5 +402,3 @@
 
 	return $m[1] . $m[6];
 }
-
-add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop()