函数文档

use_ssl_preference()

💡 云策文档标注

概述

use_ssl_preference() 是一个 WordPress 函数,用于在用户个人选项中添加可选的 SSL 偏好设置。它通过钩子到 'personal_options' 动作来实现,允许用户启用 SSL 连接。

关键要点

  • 函数用途:在用户个人资料页面添加一个复选框,让用户选择是否使用 SSL 连接。
  • 钩子动作:必须通过 'personal_options' 动作来调用此函数,以正确集成到 WordPress 界面中。
  • 参数:接受一个 WP_User 对象作为必需参数,用于获取或设置用户的 SSL 偏好。
  • 相关函数:使用 checked() 函数输出 HTML checked 属性,_e() 函数用于翻译文本。
  • 版本历史:自 WordPress 2.7.0 版本引入。

代码示例

function use_ssl_preference( $user ) {
    ?>
    <tr>
        <th scope="row"><?php _e( 'Use SSL' ); ?></th>
        <td>
            <label for="use_ssl">
                <input name="use_ssl" type="checkbox" id="use_ssl" value="1" <?php checked( $user->use_ssl ); ?> />
                <?php _e( 'Always use SSL when visiting the admin' ); ?>
            </label>
        </td>
    </tr>
    <?php
}

📄 原文内容

Optional SSL preference that can be turned on by hooking to the ‘personal_options’ action.

Description

See the ‘personal_options’ action.

Parameters

$userWP_Userrequired
User data object.

Source

function use_ssl_preference( $user ) {
?>
<tr class="user-use-ssl-wrap">
<th scope="row"></th>
<td><label for="use_ssl"><input name="use_ssl" type="checkbox" id="use_ssl" value="1" <?php checked( '1', $user->use_ssl ); ?> /> </label></td>
</tr>

</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-admin/includes/user.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/user.php#L593">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/user.php#L593-L600">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/checked/">checked()</a><code>wp-includes/general-template.php

Outputs the HTML checked attribute.

_e()wp-includes/l10n.php

Displays translated text.

Changelog

Version Description
2.7.0 Introduced.