]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/shortcodes.php
WordPress 4.3
[autoinstalls/wordpress.git] / wp-includes / shortcodes.php
index 810db20076918d7fad44bc848ff0ff0a28ede7d4..c63958b12f5e78c4bf7368b0fd1448ff8818b3db 100644 (file)
@@ -81,16 +81,14 @@ $shortcode_tags = array();
  *
  * @since 2.5.0
  *
  *
  * @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;
  * @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;
 }
 
 /**
 }
 
 /**
@@ -98,7 +96,7 @@ function add_shortcode($tag, $func) {
  *
  * @since 2.5.0
  *
  *
  * @since 2.5.0
  *
- * @uses $shortcode_tags
+ * @global array $shortcode_tags
  *
  * @param string $tag Shortcode tag to remove hook for.
  */
  *
  * @param string $tag Shortcode tag to remove hook for.
  */
@@ -117,7 +115,7 @@ function remove_shortcode($tag) {
  *
  * @since 2.5.0
  *
  *
  * @since 2.5.0
  *
- * @uses $shortcode_tags
+ * @global array $shortcode_tags
  */
 function remove_all_shortcodes() {
        global $shortcode_tags;
  */
 function remove_all_shortcodes() {
        global $shortcode_tags;
@@ -210,10 +208,10 @@ function do_shortcode( $content, $ignore_html = false ) {
 
        $pattern = get_shortcode_regex();
        $content = preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content );
 
        $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 );
        // Always restore square braces so we don't break things like <!--[if IE ]>
        $content = unescape_invalid_shortcodes( $content );
-       
+
        return $content;
 }
 
        return $content;
 }
 
@@ -234,7 +232,7 @@ function do_shortcode( $content, $ignore_html = false ) {
  *
  * @since 2.5.0
  *
  *
  * @since 2.5.0
  *
- * @uses $shortcode_tags
+ * @global array $shortcode_tags
  *
  * @return string The shortcode search regular expression
  */
  *
  * @return string The shortcode search regular expression
  */
@@ -282,10 +280,11 @@ function get_shortcode_regex() {
  *
  * @since 2.5.0
  * @access private
  *
  * @since 2.5.0
  * @access private
- * @uses $shortcode_tags
+ *
+ * @global array $shortcode_tags
  *
  * @param array $m Regular expression match array
  *
  * @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;
  */
 function do_shortcode_tag( $m ) {
        global $shortcode_tags;
@@ -298,6 +297,12 @@ function do_shortcode_tag( $m ) {
        $tag = $m[2];
        $attr = shortcode_parse_atts( $m[3] );
 
        $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];
        if ( isset( $m[5] ) ) {
                // enclosing tag - extra parameter
                return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, $m[5], $tag ) . $m[6];
@@ -326,7 +331,7 @@ function do_shortcodes_in_html_tags( $content, $ignore_html ) {
        $trans = array( '&#91;' => '&#091;', '&#93;' => '&#093;' );
        $content = strtr( $content, $trans );
        $trans = array( '[' => '&#91;', ']' => '&#93;' );
        $trans = array( '&#91;' => '&#091;', '&#93;' => '&#093;' );
        $content = strtr( $content, $trans );
        $trans = array( '[' => '&#91;', ']' => '&#93;' );
-       
+
        $pattern = get_shortcode_regex();
        $textarr = wp_html_split( $content );
 
        $pattern = get_shortcode_regex();
        $textarr = wp_html_split( $content );
 
@@ -363,14 +368,14 @@ function do_shortcodes_in_html_tags( $content, $ignore_html ) {
                        $element = strtr( $element, $trans );
                        continue;
                }
                        $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];
                // 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, '[' );
                // Look for shortcodes in each attribute separately.
                foreach ( $attributes as &$attr ) {
                        $open = strpos( $attr, '[' );
@@ -394,7 +399,7 @@ function do_shortcodes_in_html_tags( $content, $ignore_html ) {
                                if ( $count > 0 ) {
                                        // Sanitize the shortcode output using KSES.
                                        $new_attr = wp_kses_one_attr( $new_attr, $elname );
                                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;
                                        }
                                                // The shortcode is safe to use now.
                                                $attr = $new_attr;
                                        }
@@ -402,13 +407,13 @@ function do_shortcodes_in_html_tags( $content, $ignore_html ) {
                        }
                }
                $element = $front . implode( '', $attributes ) . $back;
                        }
                }
                $element = $front . implode( '', $attributes ) . $back;
-               
+
                // Now encode any remaining [ or ] chars.
                $element = strtr( $element, $trans );
        }
                // Now encode any remaining [ or ] chars.
                $element = strtr( $element, $trans );
        }
-       
+
        $content = implode( '', $textarr );
        $content = implode( '', $textarr );
-       
+
        return $content;
 }
 
        return $content;
 }
 
@@ -424,7 +429,7 @@ function unescape_invalid_shortcodes( $content ) {
         // Clean up entire string, avoids re-parsing HTML.
         $trans = array( '&#91;' => '[', '&#93;' => ']' );
         $content = strtr( $content, $trans );
         // Clean up entire string, avoids re-parsing HTML.
         $trans = array( '&#91;' => '[', '&#93;' => ']' );
         $content = strtr( $content, $trans );
-        
+
         return $content;
 }
 
         return $content;
 }
 
@@ -442,7 +447,7 @@ function unescape_invalid_shortcodes( $content ) {
  */
 function shortcode_parse_atts($text) {
        $atts = array();
  */
 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) {
        $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text);
        if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) {
                foreach ($match as $m) {
@@ -457,15 +462,6 @@ function shortcode_parse_atts($text) {
                        elseif (isset($m[8]))
                                $atts[] = stripcslashes($m[8]);
                }
                        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);
        }
        } else {
                $atts = ltrim($text);
        }
@@ -484,8 +480,8 @@ function shortcode_parse_atts($text) {
  *
  * @since 2.5.0
  *
  *
  * @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.
  */
  * @param string $shortcode Optional. The name of the shortcode, provided for context to enable filtering
  * @return array Combined and filtered attribute list.
  */
@@ -506,9 +502,9 @@ function shortcode_atts( $pairs, $atts, $shortcode = '' ) {
         *
         * @since 3.6.0
         *
         *
         * @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 $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 );
         */
        if ( $shortcode )
                $out = apply_filters( "shortcode_atts_{$shortcode}", $out, $pairs, $atts );
@@ -521,7 +517,7 @@ function shortcode_atts( $pairs, $atts, $shortcode = '' ) {
  *
  * @since 2.5.0
  *
  *
  * @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.
  *
  * @param string $content Content to remove shortcode tags.
  * @return string Content without shortcode tags.
@@ -543,10 +539,15 @@ function strip_shortcodes( $content ) {
 
        // Always restore square braces so we don't break things like <!--[if IE ]>
        $content = unescape_invalid_shortcodes( $content );
 
        // Always restore square braces so we don't break things like <!--[if IE ]>
        $content = unescape_invalid_shortcodes( $content );
-       
+
        return $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] == ']' ) {
 function strip_shortcode_tag( $m ) {
        // allow [[foo]] syntax for escaping a tag
        if ( $m[1] == '[' && $m[6] == ']' ) {