get_the_password_form

Retrieve protected post password form content.

Description

(string) get_the_password_form( (int) $post = 0 ); 

Returns (string)

HTML content for password form for password protected post.

Parameters (1)

0. $post — Optional. (int)
Post ID or WP_Post object. Default is global $post.

Usage

  1. if ( !function_exists( 'get_the_password_form' ) ) { 
  2. require_once ABSPATH . WPINC . '/post-template.php'; 
  3.  
  4. // Optional. Post ID or WP_Post object. Default is global $post. 
  5. $post = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_the_password_form($post); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post-template.php  
  1. function get_the_password_form( $post = 0 ) { 
  2. $post = get_post( $post ); 
  3. $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID ); 
  4. $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post"> 
  5. <p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p> 
  6. <p><label for="' . $label . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr_x( 'Enter', 'post password form' ) . '" /></p></form> 
  7. '; 
  8.  
  9. /** 
  10. * Filters the HTML output for the protected post password form. 
  11. * If modifying the password field, please note that the core database schema 
  12. * limits the password field to 20 characters regardless of the value of the 
  13. * size attribute in the form input. 
  14. * @since 2.7.0 
  15. * @param string $output The password form HTML output. 
  16. */ 
  17. return apply_filters( 'the_password_form', $output );