函数文档

get_shortcode_atts_regex()

💡 云策文档标注

概述

get_shortcode_atts_regex() 函数用于获取短代码属性解析的正则表达式,返回一个字符串形式的正则表达式,用于匹配短代码中的属性键值对。

关键要点

  • 函数返回一个正则表达式字符串,用于解析短代码属性。
  • 正则表达式支持多种属性格式,包括带引号和不带引号的键值对。
  • 该函数自 WordPress 4.4.0 版本引入。

代码示例

function get_shortcode_atts_regex() {
	return '/([w-]+)s*=s*"([^"]*)"(?:s|$)|([w-]+)s*=s*'([^']*)'(?:s|$)|([w-]+)s*=s*([^s'"]+)(?:s|$)|"([^"]*)"(?:s|$)|'([^']*)'(?:s|$)|(S+)(?:s|$)/';
}

注意事项

  • 正则表达式设计用于短代码属性解析,开发者应确保在相关上下文中使用,如 shortcode_parse_atts() 函数。
  • 函数返回的表达式是固定的,不建议直接修改,以避免兼容性问题。

📄 原文内容

Retrieves the shortcode attributes regex.

Return

string The shortcode attribute regular expression.

Source

function get_shortcode_atts_regex() {
	return '/([w-]+)s*=s*"([^"]*)"(?:s|$)|([w-]+)s*=s*'([^']*)'(?:s|$)|([w-]+)s*=s*([^s'"]+)(?:s|$)|"([^"]*)"(?:s|$)|'([^']*)'(?:s|$)|(S+)(?:s|$)/';
}

Changelog

Version Description
4.4.0 Introduced.