make_url_footnote()
云策文档标注
概述
make_url_footnote() 是一个已弃用的 WordPress 函数,用于从内容中提取链接并移至底部,以数字形式列出。
关键要点
- 函数功能:从输入内容中移除所有链接,并将它们以数字列表形式放置在内容底部。
- 参数:接受一个字符串参数 $content,表示要处理的内容。
- 返回值:返回处理后的字符串,其中 HTML 链接已被移除并移至底部。
- 弃用状态:自 WordPress 2.9.0 版本起已弃用,建议使用替代方法。
- 相关函数:与 _deprecated_function() 和 the_content_rss() 等相关。
代码示例
function make_url_footnote( $content ) {
_deprecated_function( __FUNCTION__, '2.9.0', '' );
preg_match_all( '/(.+?)/', $content, $matches );
$links_summary = "n";
for ( $i = 0, $c = count( $matches[0] ); $i < $c; $i++ ) {
$links_summary .= "n" . ( $i + 1 ) . ". " . $matches[0][$i];
}
$content = preg_replace( '/(.+?)/', '', $content );
return $content . $links_summary;
}注意事项
- 此函数已弃用,不应在新代码中使用,以避免兼容性问题。
- 函数内部使用正则表达式匹配链接,可能不适用于所有 HTML 结构。
- 弃用信息通过 _deprecated_function() 记录,有助于开发者识别过时代码。
原文内容
Strip HTML and put links at the bottom of stripped content.
Description
Searches for all of the links, strips them out of the content, and places them at the bottom of the content with numbers.
Parameters
$contentstringrequired-
Content to get links.
Source
function make_url_footnote( $content ) {
_deprecated_function( __FUNCTION__, '2.9.0', '' );
preg_match_all( '/<a(.+?)href="(.+?)"(.*?)>(.+?)</a>/', $content, $matches );
$links_summary = "n";
for ( $i = 0, $c = count( $matches[0] ); $i < $c; $i++ ) {
$link_match = $matches[0][$i];
$link_number = '['.($i+1).']';
$link_url = $matches[2][$i];
$link_text = $matches[4][$i];
$content = str_replace( $link_match, $link_text . ' ' . $link_number, $content );
$link_url = ( ( strtolower( substr( $link_url, 0, 7 ) ) !== 'http://' ) && ( strtolower( substr( $link_url, 0, 8 ) ) !== 'https://' ) ) ? get_option( 'home' ) . $link_url : $link_url;
$links_summary .= "n" . $link_number . ' ' . $link_url;
}
$content = strip_tags( $content );
$content .= $links_summary;
return $content;
}