wppaste
WordPress

get_the_password_form( int|WP_Post $post = 0 ): string

Since
1.0.0
Source
wp-includes/post-template.php:1769
Retrieves protected post password form content.

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

Reaches the database via get_post().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
44–46

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 47.

Plugin surface
1 hook

Third-party callbacks on 'the_password_form' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksapply_filters()called directly

Further down the call graph this can also reach option, cache, serialize and transient. 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 get_the_password_form() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!empty($post)44get_post(), site_url(), esc_url(), __(), __(), esc_attr_x(), apply_filters()
empty($post)46get_post(), rand(), site_url(), esc_url(), __(), __(), esc_attr_x(), apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev4744–461
8.54744–461
8.44744–461
8.34744–461
8.24744–461
8.14744–4612 fewer instructions than PHP 7.4
7.44945–471

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 · 1

One hook fires while get_the_password_form() runs, in this order:

  1. apply_filters( the_password_form )filterline 1791 (+22 into the body)

    Filters the HTML output for the protected post password form.

Uses · 6

  • get_post()Retrieves post data given a post ID or post object.
  • 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.
  • __()Retrieves the translation of $text.
  • esc_attr_x()Translates string with gettext context, and escapes it for safe use in an attribute.
  • apply_filters()Calls the callback functions that have been added to a filter hook.

Used by · 1

Source code

function get_the_password_form( $post = 0 ) {	$post   = get_post( $post );	$label  = 'pwbox-' . ( empty( $post->ID ) ? rand() : $post->ID );	$output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post">	<p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p>	<p><label for="' . $label . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $label . '" type="password" spellcheck="false" size="20" /></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.	 *	 * @param string  $output The password form HTML output.	 * @param WP_Post $post   Post object.	 */	return apply_filters( 'the_password_form', $output, $post );}

Changelog

Introduced in 1.0.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.7.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.