函数文档

link_xfn_meta_box()

💡 云策文档标注

概述

link_xfn_meta_box() 函数用于在 WordPress 后台显示 XFN(XHTML Friends Network)表单字段,主要用于链接编辑界面。它生成一系列复选框和输入字段,允许用户设置链接的 XFN 关系属性。

关键要点

  • 函数接受一个必需的参数 $link,表示当前链接对象,用于预填充表单值。
  • 输出包含多个 XFN 关系选项的 HTML 表单元素,如 friendship、physical、professional 等类别。
  • 使用 esc_attr() 对输出进行转义,确保安全性。
  • 函数自 WordPress 2.6.0 版本引入,属于核心功能。

代码示例

function link_xfn_meta_box( $link ) {
    // 示例代码片段:显示 link_rel 输入字段
    ?>
    <input type="text" name="link_rel" id="link_rel" value="<?php echo ( isset( $link->link_rel ) ? esc_attr( $link->link_rel ) : '' ); ?>" />
    <?php
}

注意事项

  • 此函数主要用于后台管理界面,不应直接在前端调用。
  • 相关函数包括 xfn_check()、_ex()、_e()、__() 和 esc_attr(),用于辅助处理和本地化。

📄 原文内容

Displays XFN form fields.

Parameters

$linkobjectrequired
Current link object.

Source

function link_xfn_meta_box( $link ) {
?>
<table class="links-table">
<tr>
<th scope="row"><label for="link_rel"></label></th>
<td><input type="text" name="link_rel" id="link_rel" value="<?php echo ( isset( $link->link_rel ) ? esc_attr( $link->link_rel ) : '' ); ?>" /></td>
</tr>

<tr>
<th scope="row"></th>
<td><fieldset>
<legend class="screen-reader-text"><span></span></legend>
<label for="me">
<input type="checkbox" name="identity" value="me" id="me" <?php xfn_check( 'identity', 'me' ); ?> />
</label>
</fieldset></td>
</tr>

<tr>
<th scope="row"></th>
<td><fieldset>
<legend class="screen-reader-text"><span></span></legend>
<label for="contact">
<input class="valinp" type="radio" name="friendship" value="contact" id="contact" <?php xfn_check( 'friendship', 'contact' ); ?> /> 
</label>
<label for="acquaintance">
<input class="valinp" type="radio" name="friendship" value="acquaintance" id="acquaintance" <?php xfn_check( 'friendship', 'acquaintance' ); ?> /> 
</label>
<label for="friend">
<input class="valinp" type="radio" name="friendship" value="friend" id="friend" <?php xfn_check( 'friendship', 'friend' ); ?> /> 
</label>
<label for="friendship">
<input name="friendship" type="radio" class="valinp" value="" id="friendship" <?php xfn_check( 'friendship' ); ?> /> 
</label>
</fieldset></td>
</tr>

<tr>
<th scope="row"> </th>
<td><fieldset>
<legend class="screen-reader-text"><span></span></legend>
<label for="met">
<input class="valinp" type="checkbox" name="physical" value="met" id="met" <?php xfn_check( 'physical', 'met' ); ?> /> 
</label>
</fieldset></td>
</tr>

<tr>
<th scope="row"> </th>
<td><fieldset>
<legend class="screen-reader-text"><span></span></legend>
<label for="co-worker">
<input class="valinp" type="checkbox" name="professional" value="co-worker" id="co-worker" <?php xfn_check( 'professional', 'co-worker' ); ?> /> 
</label>
<label for="colleague">
<input class="valinp" type="checkbox" name="professional" value="colleague" id="colleague" <?php xfn_check( 'professional', 'colleague' ); ?> /> 
</label>
</fieldset></td>
</tr>

<tr>
<th scope="row"></th>
<td><fieldset>
<legend class="screen-reader-text"><span></span></legend>
<label for="co-resident">
<input class="valinp" type="radio" name="geographical" value="co-resident" id="co-resident" <?php xfn_check( 'geographical', 'co-resident' ); ?> /> 
</label>
<label for="neighbor">
<input class="valinp" type="radio" name="geographical" value="neighbor" id="neighbor" <?php xfn_check( 'geographical', 'neighbor' ); ?> /> 
</label>
<label for="geographical">
<input class="valinp" type="radio" name="geographical" value="" id="geographical" <?php xfn_check( 'geographical' ); ?> /> 
</label>
</fieldset></td>
</tr>

<tr>
<th scope="row"></th>
<td><fieldset>
<legend class="screen-reader-text"><span></span></legend>
<label for="child">
<input class="valinp" type="radio" name="family" value="child" id="child" <?php xfn_check( 'family', 'child' ); ?> /> 
</label>
<label for="kin">
<input class="valinp" type="radio" name="family" value="kin" id="kin" <?php xfn_check( 'family', 'kin' ); ?> /> 
</label>
<label for="parent">
<input class="valinp" type="radio" name="family" value="parent" id="parent" <?php xfn_check( 'family', 'parent' ); ?> /> 
</label>
<label for="sibling">
<input class="valinp" type="radio" name="family" value="sibling" id="sibling" <?php xfn_check( 'family', 'sibling' ); ?> /> 
</label>
<label for="spouse">
<input class="valinp" type="radio" name="family" value="spouse" id="spouse" <?php xfn_check( 'family', 'spouse' ); ?> /> 
</label>
<label for="family">
<input class="valinp" type="radio" name="family" value="" id="family" <?php xfn_check( 'family' ); ?> /> 
</label>
</fieldset></td>
</tr>

<tr>
<th scope="row"></th>
<td><fieldset>
<legend class="screen-reader-text"><span></span></legend>
<label for="muse">
<input class="valinp" type="checkbox" name="romantic" value="muse" id="muse" <?php xfn_check( 'romantic', 'muse' ); ?> /> 
</label>
<label for="crush">
<input class="valinp" type="checkbox" name="romantic" value="crush" id="crush" <?php xfn_check( 'romantic', 'crush' ); ?> /> 
</label>
<label for="date">
<input class="valinp" type="checkbox" name="romantic" value="date" id="date" <?php xfn_check( 'romantic', 'date' ); ?> /> 
</label>
<label for="romantic">
<input class="valinp" type="checkbox" name="romantic" value="sweetheart" id="romantic" <?php xfn_check( 'romantic', 'sweetheart' ); ?> /> 
</label>
</fieldset></td>
</tr>

</table>
<p>XFN</a>.' ); ?></p>
</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-admin/includes/meta-boxes.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/meta-boxes.php#L1312">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/meta-boxes.php#L1312-L1435">View on GitHub</a></p></section>

<section class="wp-block-wporg-code-reference-related" data-nosnippet="true"><h2 id="related" class="is-toc-heading wp-block-heading has-heading-5-font-size" tabindex="-1" ><a href="#related">Related</a></h2> <section style="margin-top:var(--wp--preset--spacing--20)" class="wp-block-wporg-code-table" id="uses"><figure class="wp-block-table "><table><thead><tr><th scope="col">Uses</th><th scope="col">Description</th></tr></thead><tbody><tr class=""><td><a href="https://developer.wordpress.org/reference/functions/xfn_check/">xfn_check()</a><code>wp-admin/includes/meta-boxes.php

Displays ‘checked’ checkboxes attribute for XFN microformat options.

_ex()wp-includes/l10n.php

Displays translated string with gettext context.

_e()wp-includes/l10n.php

Displays translated text.

__()wp-includes/l10n.php

Retrieves the translation of $text.

esc_attr()wp-includes/formatting.php

Escaping for HTML attributes.

Show 3 moreShow less

Changelog

Version Description
2.6.0 Introduced.