do_shortcode_tag
apply_filters( ‘do_shortcode_tag’, string $output , string $tag , array|string $attr , array $m )
过滤器::过滤由快捷方式回调创建的输出。
Filter Hook: Filters the output created by a shortcode callback.
参数(Parameters)
参数 | 类型 | 说明 |
---|---|---|
$output | (string) | 短路输出。 |
$tag | (string) | 快捷方式名称。 |
$attr | (array | string) | 快捷方式属性数组或空字符串。 |
$m | (array) | 正则表达式匹配数组。 |
源码(Source)
/** * 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 * @access private * * @global array $shortcode_tags * * @param array $m Regular expression match array * @return string|false False on failure. */ function do_shortcode_tag( $m ) { global $shortcode_tags; // allow [[foo]] syntax for escaping a tag if ( $m[1] == '[' && $m[6] == ']' ) { return substr($m[0], 1, -1); } $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]; } else { // self-closing tag return $m[1] . call_user_func( $shortcode_tags[$tag], $attr, null, $tag ) . $m[6]; } }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
4.7.0 | wp-includes/shortcodes.php:355 | 1 | 0 |
笔记(Notes)
另一个有用的功能是将特定于快捷方式的脚本排队,
此筛选器对于在快捷方式(例如内联脚本)末尾添加其他内容非常有用,
do_shortcode_tag 为WP2原创文章,链接:https://www.wp2.cn/hook/do_shortcode_tag/