wpseek.com
A WordPress-centric search engine for devs and theme authors
get_the_password_form › WordPress Function
Since1.0.0
Deprecatedn/a
› get_the_password_form ( $post = 0 )
Parameters: |
|
Returns: |
|
Defined at: |
|
Codex: |
Retrieves protected post password form content.
Related Functions: get_the_author_aim, get_the_author_msn, get_the_author_yim, get_the_author_firstname, get_the_author_url
Source
function get_the_password_form( $post = 0 ) {
$post = get_post( $post );
$field_id = 'pwbox-' . ( empty( $post->ID ) ? wp_rand() : $post->ID );
$invalid_password = '';
$invalid_password_html = '';
$aria = '';
$class = '';
$redirect_field = '';
// If the referrer is the same as the current request, the user has entered an invalid password.
if ( ! empty( $post->ID ) && wp_get_raw_referer() === get_permalink( $post->ID ) && isset( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ) ) {
/**
* Filters the invalid password message shown on password-protected posts.
* The filter is only applied if the post is password protected.
*
* @since 6.8.0
*
* @param string $text The message shown to users when entering an invalid password.
* @param WP_Post $post Post object.
*/
$invalid_password = apply_filters( 'the_password_form_incorrect_password', __( 'Invalid password.' ), $post );
$invalid_password_html = '<div class="post-password-form-invalid-password" role="alert"><p id="error-' . $field_id . '">' . $invalid_password . '</p></div>';
$aria = ' aria-describedby="error-' . $field_id . '"';
$class = ' password-form-error';
}
if ( ! empty( $post->ID ) ) {
$redirect_field = sprintf(
'<input type="hidden" name="redirect_to" value="%s" />',
esc_attr( get_permalink( $post->ID ) )
);
}
$output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form' . $class . '" method="post">' . $redirect_field . $invalid_password_html . '
<p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p>
<p><label for="' . $field_id . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $field_id . '" type="password" spellcheck="false" required size="20"' . $aria . ' /></label> <input type="submit" name="Submit" value="' . esc_attr_x( 'Enter', 'post password form' ) . '" /></p></form>
';
/**
* Filters the HTML output for the protected post password form.
*
* 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.
*
* @since 2.7.0
* @since 5.8.0 Added the `$post` parameter.
* @since 6.8.0 Added the `$invalid_password` parameter.
*
* @param string $output The password form HTML output.
* @param WP_Post $post Post object.
* @param string $invalid_password The invalid password message.
*/
return apply_filters( 'the_password_form', $output, $post, $invalid_password );
}