the_password_form
云策文档标注
概述
the_password_form 是一个 WordPress 过滤器,用于修改受保护文章密码表单的 HTML 输出。它允许开发者自定义表单结构和样式,并提供了参数以处理密码验证和文章对象。
关键要点
- 过滤器名称:the_password_form,用于过滤受保护文章密码表单的 HTML 输出。
- 参数:$output(表单 HTML 输出)、$post(WP_Post 对象)、$invalid_password(无效密码消息)。
- 注意事项:修改密码字段时,需注意 WordPress 数据库模式将密码字段限制为 255 个字符,不受 minlength 或 maxlength 属性影响。
- 相关函数:get_the_password_form() 用于检索受保护文章密码表单内容。
- 变更历史:6.8.0 版本添加 $invalid_password 参数,5.8.0 版本添加 $post 参数,2.7.0 版本引入。
代码示例
function wpdocs_custom_password_form() {
global $post;
$loginurl = site_url() . '/wp-login.php?action=postpass';
$label = 'pwbox-' . ( ! empty( $post->ID ) ? $post->ID : rand() );
ob_start();
?>
<form action="<?php echo esc_url( $loginurl ); ?>" method="post" class="center-custom search-form" role="search">
<label for="<?php echo esc_attr( $label ); ?>" class="post-password-label">
<input id="<?php echo esc_attr( $label ); ?>" class="input post-password-class" type="text" placeholder="Enter your access code provided by your concierge" />
<input type="submit" name="Submit" value="Submit" />
</label>
</form>
<?php
return ob_get_clean();
}
原文内容
Filters the HTML output for the protected post password form.
Description
If modifying the password field, please note that the WordPress database schema limits the password field to 255 characters regardless of the value of the minlength or maxlength attributes or other validation that may be added to the input.
Parameters
$outputstring-
The password form HTML output.
$postWP_Post-
Post object.
$invalid_passwordstring-
The invalid password message.
Source
return apply_filters( 'the_password_form', $output, $post, $invalid_password );
Skip to note 2 content
Deepak Lakhara
This is a working example and 9999 is the priority and you can adjust accordingly.