shortcode_atts()
shortcode_atts( array $pairs, array $atts, string $shor…
shortcode_atts( array $pairs, array $atts, string $shortcode = ” )
结合用户属性和已知属性,并在需要时填写默认值。
		Combine user attributes with known attributes and fill in defaults when needed.
	
目录锚点:#说明#参数#源码#笔记
说明(Description)
这些对应该被认为是调用者支持的所有属性,并以列表的形式给出。返回的属性将只包含$pairs列表中的属性。如果$atts列表包含不受支持的属性,则它们将被忽略并从最终返回的列表中删除。
参数(Parameters)
| 参数 | 类型 | 说明 | 
|---|---|---|
| $pairs | (array) | 支持的属性及其默认值的完整列表。 | 
| $atts | (array) | 快捷代码标记中的用户定义属性。 | 
| $shortcode | (string) | 为上下文提供的用于启用筛选的短代码的名称 | 
源码(Source)
/**
 * Combine user attributes with known attributes and fill in defaults when needed.
 *
 * The pairs should be considered to be all of the attributes which are
 * supported by the caller and given as a list. The returned attributes will
 * only contain the attributes in the $pairs list.
 *
 * If the $atts list has unsupported attributes, then they will be ignored and
 * removed from the final returned list.
 *
 * @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 string $shortcode Optional. The name of the shortcode, provided for context to enable filtering
 * @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;
	}
	/**
	 * Filter a shortcode's default attributes.
	 *
	 * If the third parameter of the shortcode_atts() function is present then this filter is available.
	 * The third parameter, $shortcode, is the name of the shortcode.
	 *
	 * @since 3.6.0
	 *
	 * @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.
	 */
	if ( $shortcode )
		$out = apply_filters( "shortcode_atts_{$shortcode}", $out, $pairs, $atts );
	return $out;
}| 更新版本 | 源码位置 | 使用 | 被使用 | 
|---|---|---|---|
| 2.5.0 | wp-includes/shortcodes.php | 1 | 9 | 
笔记(Notes)
例子
类别:WordPress 函数手册、 
		本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。





还没有任何评论,赶紧来占个楼吧!