对我来说,此代码有效:
function my_password_form() {
global $post;
$label = \'pwbox-\'.( empty( $post->ID ) ? rand() : $post->ID );
$passwordProtectedPageURL = get_the_permalink();
$wrongPassword = \' \';
if( ( sanitize_text_field( $_SERVER["HTTP_REFERER"] ) === $passwordProtectedPageURL ) && isset ( $_COOKIE[ \'wp-postpass_\' . COOKIEHASH ] )){
$wrongPassword = \'<span style="color:#ed1b24;font-weight:bold;">Contraseña incorrecta, por favor inténtalo de nuevo.</span>\';
setcookie (\'wp-postpass_\' . COOKIEHASH, null, -1);
}
$form = \'<form action="\' . esc_url( site_url( \'wp-login.php?action=postpass\', \'login_post\' ) ) . \'" method="post" class="post-password-form">
\' . "<p>Este contenido está protegido por contraseña. Para verlo, por favor, introduce tu contraseña a continuación:</p>" . \'
<p><label for="\' . $label . \'">\' . __( "Password:" ) . \' <input name="post_password" id="\' . $label . \'" type="password" size="20" maxlength="20" /></label>
<input type="submit" name="Submit" value="\' . esc_attr__( "Submit" ) . \'" /></p>
</form><p>\' . $wrongPassword . \'</p>\';
return $form;
}
add_filter( \'the_password_form\', \'my_password_form\' );
这些信息是西班牙语的,但很容易更改。