mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
Code is Poetry.
WordPress' code just... wasn't. This is now dealt with. Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS. Fixes #41057. git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -88,10 +88,10 @@ function add_shortcode( $tag, $callback ) {
|
||||
*
|
||||
* @param string $tag Shortcode tag to remove hook for.
|
||||
*/
|
||||
function remove_shortcode($tag) {
|
||||
function remove_shortcode( $tag ) {
|
||||
global $shortcode_tags;
|
||||
|
||||
unset($shortcode_tags[$tag]);
|
||||
unset( $shortcode_tags[ $tag ] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,8 +144,9 @@ function has_shortcode( $content, $tag ) {
|
||||
|
||||
if ( shortcode_exists( $tag ) ) {
|
||||
preg_match_all( '/' . get_shortcode_regex() . '/', $content, $matches, PREG_SET_ORDER );
|
||||
if ( empty( $matches ) )
|
||||
if ( empty( $matches ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ( $matches as $shortcode ) {
|
||||
if ( $tag === $shortcode[2] ) {
|
||||
@@ -180,8 +181,9 @@ function do_shortcode( $content, $ignore_html = false ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
if (empty($shortcode_tags) || !is_array($shortcode_tags))
|
||||
if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Find all registered tag names in $content.
|
||||
preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches );
|
||||
@@ -231,7 +233,7 @@ function get_shortcode_regex( $tagnames = null ) {
|
||||
if ( empty( $tagnames ) ) {
|
||||
$tagnames = array_keys( $shortcode_tags );
|
||||
}
|
||||
$tagregexp = join( '|', array_map('preg_quote', $tagnames) );
|
||||
$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.
|
||||
@@ -271,6 +273,7 @@ function get_shortcode_regex( $tagnames = null ) {
|
||||
|
||||
/**
|
||||
* Regular Expression callable for do_shortcode() for calling shortcode hook.
|
||||
*
|
||||
* @see get_shortcode_regex for details of the match array contents.
|
||||
*
|
||||
* @since 2.5.0
|
||||
@@ -286,10 +289,10 @@ function do_shortcode_tag( $m ) {
|
||||
|
||||
// allow [[foo]] syntax for escaping a tag
|
||||
if ( $m[1] == '[' && $m[6] == ']' ) {
|
||||
return substr($m[0], 1, -1);
|
||||
return substr( $m[0], 1, -1 );
|
||||
}
|
||||
|
||||
$tag = $m[2];
|
||||
$tag = $m[2];
|
||||
$attr = shortcode_parse_atts( $m[3] );
|
||||
|
||||
if ( ! is_callable( $shortcode_tags[ $tag ] ) ) {
|
||||
@@ -351,9 +354,15 @@ function do_shortcode_tag( $m ) {
|
||||
*/
|
||||
function do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ) {
|
||||
// Normalize entities in unfiltered HTML before adding placeholders.
|
||||
$trans = array( '[' => '[', ']' => ']' );
|
||||
$trans = array(
|
||||
'[' => '[',
|
||||
']' => ']',
|
||||
);
|
||||
$content = strtr( $content, $trans );
|
||||
$trans = array( '[' => '[', ']' => ']' );
|
||||
$trans = array(
|
||||
'[' => '[',
|
||||
']' => ']',
|
||||
);
|
||||
|
||||
$pattern = get_shortcode_regex( $tagnames );
|
||||
$textarr = wp_html_split( $content );
|
||||
@@ -363,7 +372,7 @@ function do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$noopen = false === strpos( $element, '[' );
|
||||
$noopen = false === strpos( $element, '[' );
|
||||
$noclose = false === strpos( $element, ']' );
|
||||
if ( $noopen || $noclose ) {
|
||||
// This element does not contain shortcodes.
|
||||
@@ -393,15 +402,15 @@ function do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ) {
|
||||
}
|
||||
|
||||
// Get element name
|
||||
$front = array_shift( $attributes );
|
||||
$back = array_pop( $attributes );
|
||||
$front = array_shift( $attributes );
|
||||
$back = array_pop( $attributes );
|
||||
$matches = array();
|
||||
preg_match('%[a-zA-Z0-9]+%', $front, $matches);
|
||||
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, '[' );
|
||||
$open = strpos( $attr, '[' );
|
||||
$close = strpos( $attr, ']' );
|
||||
if ( false === $open || false === $close ) {
|
||||
continue; // Go to next attribute. Square braces will be escaped at end of loop.
|
||||
@@ -417,7 +426,7 @@ function do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ) {
|
||||
} else {
|
||||
// $attr like 'name = "[shortcode]"' or "name = '[shortcode]'"
|
||||
// We do not know if $content was unfiltered. Assume KSES ran before shortcodes.
|
||||
$count = 0;
|
||||
$count = 0;
|
||||
$new_attr = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $attr, -1, $count );
|
||||
if ( $count > 0 ) {
|
||||
// Sanitize the shortcode output using KSES.
|
||||
@@ -449,11 +458,14 @@ function do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ) {
|
||||
* @return string Content with placeholders removed.
|
||||
*/
|
||||
function unescape_invalid_shortcodes( $content ) {
|
||||
// Clean up entire string, avoids re-parsing HTML.
|
||||
$trans = array( '[' => '[', ']' => ']' );
|
||||
$content = strtr( $content, $trans );
|
||||
// Clean up entire string, avoids re-parsing HTML.
|
||||
$trans = array(
|
||||
'[' => '[',
|
||||
']' => ']',
|
||||
);
|
||||
$content = strtr( $content, $trans );
|
||||
|
||||
return $content;
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -482,28 +494,29 @@ function get_shortcode_atts_regex() {
|
||||
* Returns empty string if trim( $text ) == ''.
|
||||
* All other matches are checked for not empty().
|
||||
*/
|
||||
function shortcode_parse_atts($text) {
|
||||
$atts = array();
|
||||
function shortcode_parse_atts( $text ) {
|
||||
$atts = array();
|
||||
$pattern = get_shortcode_atts_regex();
|
||||
$text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text);
|
||||
if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) {
|
||||
foreach ($match as $m) {
|
||||
if (!empty($m[1]))
|
||||
$atts[strtolower($m[1])] = stripcslashes($m[2]);
|
||||
elseif (!empty($m[3]))
|
||||
$atts[strtolower($m[3])] = stripcslashes($m[4]);
|
||||
elseif (!empty($m[5]))
|
||||
$atts[strtolower($m[5])] = stripcslashes($m[6]);
|
||||
elseif (isset($m[7]) && strlen($m[7]))
|
||||
$atts[] = stripcslashes($m[7]);
|
||||
elseif (isset($m[8]) && strlen($m[8]))
|
||||
$atts[] = stripcslashes($m[8]);
|
||||
elseif (isset($m[9]))
|
||||
$atts[] = stripcslashes($m[9]);
|
||||
$text = preg_replace( "/[\x{00a0}\x{200b}]+/u", ' ', $text );
|
||||
if ( preg_match_all( $pattern, $text, $match, PREG_SET_ORDER ) ) {
|
||||
foreach ( $match as $m ) {
|
||||
if ( ! empty( $m[1] ) ) {
|
||||
$atts[ strtolower( $m[1] ) ] = stripcslashes( $m[2] );
|
||||
} elseif ( ! empty( $m[3] ) ) {
|
||||
$atts[ strtolower( $m[3] ) ] = stripcslashes( $m[4] );
|
||||
} elseif ( ! empty( $m[5] ) ) {
|
||||
$atts[ strtolower( $m[5] ) ] = stripcslashes( $m[6] );
|
||||
} elseif ( isset( $m[7] ) && strlen( $m[7] ) ) {
|
||||
$atts[] = stripcslashes( $m[7] );
|
||||
} elseif ( isset( $m[8] ) && strlen( $m[8] ) ) {
|
||||
$atts[] = stripcslashes( $m[8] );
|
||||
} elseif ( isset( $m[9] ) ) {
|
||||
$atts[] = stripcslashes( $m[9] );
|
||||
}
|
||||
}
|
||||
|
||||
// Reject any unclosed HTML elements
|
||||
foreach( $atts as &$value ) {
|
||||
foreach ( $atts as &$value ) {
|
||||
if ( false !== strpos( $value, '<' ) ) {
|
||||
if ( 1 !== preg_match( '/^[^<]*+(?:<[^>]*+>[^<]*+)*+$/', $value ) ) {
|
||||
$value = '';
|
||||
@@ -511,7 +524,7 @@ function shortcode_parse_atts($text) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$atts = ltrim($text);
|
||||
$atts = ltrim( $text );
|
||||
}
|
||||
return $atts;
|
||||
}
|
||||
@@ -534,13 +547,14 @@ function shortcode_parse_atts($text) {
|
||||
* @return array Combined and filtered attribute list.
|
||||
*/
|
||||
function shortcode_atts( $pairs, $atts, $shortcode = '' ) {
|
||||
$atts = (array)$atts;
|
||||
$out = array();
|
||||
foreach ($pairs as $name => $default) {
|
||||
if ( array_key_exists($name, $atts) )
|
||||
$out[$name] = $atts[$name];
|
||||
else
|
||||
$out[$name] = $default;
|
||||
$atts = (array) $atts;
|
||||
$out = array();
|
||||
foreach ( $pairs as $name => $default ) {
|
||||
if ( array_key_exists( $name, $atts ) ) {
|
||||
$out[ $name ] = $atts[ $name ];
|
||||
} else {
|
||||
$out[ $name ] = $default;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Filters a shortcode's default attributes.
|
||||
@@ -580,8 +594,9 @@ function strip_shortcodes( $content ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
if (empty($shortcode_tags) || !is_array($shortcode_tags))
|
||||
if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Find all registered tag names in $content.
|
||||
preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches );
|
||||
@@ -626,7 +641,7 @@ function strip_shortcodes( $content ) {
|
||||
function strip_shortcode_tag( $m ) {
|
||||
// allow [[foo]] syntax for escaping a tag
|
||||
if ( $m[1] == '[' && $m[6] == ']' ) {
|
||||
return substr($m[0], 1, -1);
|
||||
return substr( $m[0], 1, -1 );
|
||||
}
|
||||
|
||||
return $m[1] . $m[6];
|
||||
|
||||
Reference in New Issue
Block a user