twenty_twenty_one_password_form( string $output, int|WP_Post $post = 0 ): string
- Since
- Twenty Twenty-One 1.0, Twenty Twenty-One 1.4 Corrected parameter name for <code>$output</code>, added the <code>$post</code> parameter.
- Source
wp-content/themes/twentytwentyone/inc/template-functions.php:431
Compatibility
- WordPress
- since Twenty Twenty-One 1.4 Corrected parameter name for <code>$output</code>, added the <code>$post</code> parameter.
- 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
$outputstring- The password form HTML output.
$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 twenty_twenty_one_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
- 58–61
- Plugin surface
- None
- Called by
- 0
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 62.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- querycontent query
get_post()called directly - transienttransient
get_transient()one call below twenty_twenty_one_password_form() - hookthird-party callbacks
apply_filters()one call below twenty_twenty_one_password_form()
Further down the call graph this can also reach cache, option 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 · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost twenty_twenty_one_password_form() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!empty($post) | 58 | get_post(), esc_html__(), site_url(), esc_url(), esc_attr(), esc_html_x(), esc_attr(), esc_attr_x(), esc_attr_x() |
empty($post) | 61 | get_post(), wp_rand(), esc_html__(), site_url(), esc_url(), esc_attr(), esc_html_x(), esc_attr(), esc_attr_x(), esc_attr_x() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 61 | 58–60 | 1 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 62 | 58–61 | 1 | |
| 8.4 | 62 | 58–61 | 1 | |
| 8.3 | 62 | 58–61 | 1 | |
| 8.2 | 62 | 58–61 | 1 | |
| 8.1 | 62 | 58–61 | 1 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 63 | 59–61 | 1 |
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.
Uses · 8
- get_post()Retrieves post data given a post ID or post object.
- wp_rand()Generates a random non-negative number.
- esc_html__()Retrieves the translation of $text and escapes it for safe use in HTML output.
- 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()Escaping for HTML attributes.
- esc_html_x()Translates string with gettext context, and escapes it for safe use in HTML output.
- esc_attr_x()Translates string with gettext context, and escapes it for safe use in an attribute.
Source code
function twenty_twenty_one_password_form( $output, $post = 0 ) { $post = get_post( $post ); $label = 'pwbox-' . ( empty( $post->ID ) ? wp_rand() : $post->ID ); $output = '<p class="post-password-message">' . esc_html__( 'This content is password protected. Please enter a password to view.', 'twentytwentyone' ) . '</p> <form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post"> <label class="post-password-form__label" for="' . esc_attr( $label ) . '">' . esc_html_x( 'Password', 'Post password form', 'twentytwentyone' ) . '</label><input class="post-password-form__input" name="post_password" id="' . esc_attr( $label ) . '" type="password" spellcheck="false" size="20" /><input type="submit" class="post-password-form__submit" name="' . esc_attr_x( 'Submit', 'Post password form', 'twentytwentyone' ) . '" value="' . esc_attr_x( 'Enter', 'Post password form', 'twentytwentyone' ) . '" /></form> '; return $output;}Changelog
Introduced in Twenty Twenty-One 1.4 Corrected parameter name for <code>$output</code>, added the <code>$post</code> parameter.. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$output, added the $post parameter.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-content/themes/twentytwentyone/inc/template-functions.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.