Wordpress++
This commit is contained in:
1 parent
790f1487a2
commit
3f49ab1747
610 files changed
+58979
-36562
No files matched your search
+37
-27
@@ -81,16 +81,14 @@ $shortcode_tags = array();
|
||||
*
|
||||
* @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;
|
||||
|
||||
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
|
||||
*
|
||||
* @uses $shortcode_tags
|
||||
* @global array $shortcode_tags
|
||||
*
|
||||
* @param string $tag Shortcode tag to remove hook for.
|
||||
*/
|
||||
@@ -117,7 +115,7 @@ function remove_shortcode($tag) {
|
||||
*
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @uses $shortcode_tags
|
||||
* @global array $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 );
|
||||
|
||||
|
||||
// Always restore square braces so we don't break things like <!--[if IE ]>
|
||||
$content = unescape_invalid_shortcodes( $content );
|
||||
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
@@ -234,7 +232,7 @@ function do_shortcode( $content, $ignore_html = false ) {
|
||||
*
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @uses $shortcode_tags
|
||||
* @global array $shortcode_tags
|
||||
*
|
||||
* @return string The shortcode search regular expression
|
||||
*/
|
||||
@@ -282,10 +280,11 @@ function get_shortcode_regex() {
|
||||
*
|
||||
* @since 2.5.0
|
||||
* @access private
|
||||
* @uses $shortcode_tags
|
||||
*
|
||||
* @global array $shortcode_tags
|
||||
*
|
||||
* @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;
|
||||
@@ -298,6 +297,12 @@ function do_shortcode_tag( $m ) {
|
||||
$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];
|
||||
@@ -326,7 +331,7 @@ function do_shortcodes_in_html_tags( $content, $ignore_html ) {
|
||||
$trans = array( '[' => '[', ']' => ']' );
|
||||
$content = strtr( $content, $trans );
|
||||
$trans = array( '[' => '[', ']' => ']' );
|
||||
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
// 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, '[' );
|
||||
@@ -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 ( '' !== $new_attr ) {
|
||||
if ( '' !== trim( $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;
|
||||
|
||||
|
||||
// Now encode any remaining [ or ] chars.
|
||||
$element = strtr( $element, $trans );
|
||||
}
|
||||
|
||||
|
||||
$content = implode( '', $textarr );
|
||||
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
@@ -424,7 +429,7 @@ function unescape_invalid_shortcodes( $content ) {
|
||||
// Clean up entire string, avoids re-parsing HTML.
|
||||
$trans = array( '[' => '[', ']' => ']' );
|
||||
$content = strtr( $content, $trans );
|
||||
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
@@ -442,7 +447,7 @@ function unescape_invalid_shortcodes( $content ) {
|
||||
*/
|
||||
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) {
|
||||
@@ -475,8 +480,8 @@ function shortcode_parse_atts($text) {
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
@@ -497,9 +502,9 @@ function shortcode_atts( $pairs, $atts, $shortcode = '' ) {
|
||||
*
|
||||
* @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 $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 );
|
||||
@@ -512,7 +517,7 @@ function shortcode_atts( $pairs, $atts, $shortcode = '' ) {
|
||||
*
|
||||
* @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.
|
||||
@@ -534,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 );
|
||||
|
||||
|
||||
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] == ']' ) {
|
||||
|
||||
Reference in new issue
Block a user