get_the_password_form( int|WP_Post $post = 0 ): string
- Since
- 1.0.0
- Source
wp-includes/post-template.php:1776
Compatibility
- WordPress
- since 1.0.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$postint|WP_Postoptional- Post ID or WP_Post object. Default is global $post.Default:
0
Return value
string- HTML content for password form for password-protected post.
Performance profile
How much work a call to get_the_password_form() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Constant
- Instructions
- 61–108
- Plugin surface
- 2 hooks
- Called by
- 1
Reaches the database via get_post().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 109.
Third-party callbacks on 'the_password_form_incorrect_password', 'the_password_form' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()called directly - transienttransient
get_transient()one call below get_the_password_form() - optionoption read or write
get_option()one call below get_the_password_form()
Further down the call graph this can also reach cache and serialize. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 12 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_the_password_form() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 61 | get_post(), site_url(), esc_url(), __(), __(), esc_attr_x(), apply_filters() |
empty($post) | 64 | get_post(), wp_rand(), site_url(), esc_url(), __(), __(), esc_attr_x(), apply_filters() |
| always | 70–75 | get_post(), wp_get_raw_referer(), get_permalink(), site_url(), esc_url(), __(), __(), esc_attr_x(), apply_filters() |
| always | 73 | get_post(), get_permalink(), esc_attr(), site_url(), esc_url(), __(), __(), esc_attr_x(), apply_filters() |
| always | 73–78 | get_post(), wp_rand(), wp_get_raw_referer(), get_permalink(), site_url(), esc_url(), __(), __(), esc_attr_x(), apply_filters() |
| always | 76 | get_post(), wp_rand(), get_permalink(), esc_attr(), site_url(), esc_url(), __(), __(), esc_attr_x(), apply_filters() |
!empty($post) | 82–87 | get_post(), wp_get_raw_referer(), get_permalink(), get_permalink(), esc_attr(), site_url(), esc_url(), __(), __(), esc_attr_x(), apply_filters() |
| always | 85–90 | get_post(), wp_rand(), wp_get_raw_referer(), get_permalink(), get_permalink(), esc_attr(), site_url(), esc_url(), __(), __(), esc_attr_x(), apply_filters() |
isset($value) | 93 | get_post(), wp_get_raw_referer(), get_permalink(), __(), apply_filters(), site_url(), esc_url(), __(), __(), esc_attr_x(), apply_filters() |
isset($value) | 96 | get_post(), wp_rand(), wp_get_raw_referer(), get_permalink(), __(), apply_filters(), site_url(), esc_url(), __(), __(), esc_attr_x(), apply_filters() |
!empty($post) && isset($value) | 105 | get_post(), wp_get_raw_referer(), get_permalink(), __(), apply_filters(), get_permalink(), esc_attr(), site_url(), esc_url(), __(), __(), esc_attr_x(), apply_filters() |
isset($value) | 108 | get_post(), wp_rand(), wp_get_raw_referer(), get_permalink(), __(), apply_filters(), get_permalink(), esc_attr(), site_url(), esc_url(), __(), __(), esc_attr_x(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 108 | 61–107 | 5 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 109 | 61–108 | 5 | |
| 8.4 | 109 | 61–108 | 5 | 1 fewer instruction than PHP 8.3 |
| 8.3 | 110 | 61–109 | 5 | |
| 8.2 | 110 | 61–109 | 5 | |
| 8.1 | 110 | 61–109 | 5 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 111 | 62–109 | 5 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 2
2 hooks fire while get_the_password_form() runs, in this order:
- apply_filters( the_password_form_incorrect_password )filterline 1796 (+20 into the body)
Filters the invalid password message shown on password-protected posts.
- apply_filters( the_password_form )filterline 1830 (+54 into the body)
Filters the HTML output for the protected post password form.
Uses · 10
- get_post()Retrieves post data given a post ID or post object.
- wp_rand()Generates a random non-negative number.
- wp_get_raw_referer()Retrieves unvalidated referer from the '_wp_http_referer' URL query variable or the HTTP referer.
- get_permalink()Retrieves the full permalink for the current post or post ID.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- __()Retrieves the translation of $text.
- esc_attr()Escaping for HTML attributes.
- esc_url()Checks and cleans a URL.
- site_url()Retrieves the URL for the current site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.
- esc_attr_x()Translates string with gettext context, and escapes it for safe use in an attribute.
Used by · 1
- get_the_content()Retrieves the post content.
Source code
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 the 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 );}Changelog
Introduced in 1.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/post-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.