wp/wp-includes/post-template.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
   673 
   673 
   674 	if ( is_singular() ) {
   674 	if ( is_singular() ) {
   675 		$post      = $wp_query->get_queried_object();
   675 		$post      = $wp_query->get_queried_object();
   676 		$post_id   = $post->ID;
   676 		$post_id   = $post->ID;
   677 		$post_type = $post->post_type;
   677 		$post_type = $post->post_type;
       
   678 
       
   679 		$classes[] = 'wp-singular';
   678 
   680 
   679 		if ( is_page_template() ) {
   681 		if ( is_page_template() ) {
   680 			$classes[] = "{$post_type}-template";
   682 			$classes[] = "{$post_type}-template";
   681 
   683 
   682 			$template_slug  = get_page_template_slug( $post_id );
   684 			$template_slug  = get_page_template_slug( $post_id );
   832 		} elseif ( is_search() ) {
   834 		} elseif ( is_search() ) {
   833 			$classes[] = 'search-paged-' . $page;
   835 			$classes[] = 'search-paged-' . $page;
   834 		} elseif ( is_post_type_archive() ) {
   836 		} elseif ( is_post_type_archive() ) {
   835 			$classes[] = 'post-type-paged-' . $page;
   837 			$classes[] = 'post-type-paged-' . $page;
   836 		}
   838 		}
       
   839 	}
       
   840 
       
   841 	$classes[] = 'wp-theme-' . sanitize_html_class( get_template() );
       
   842 	if ( is_child_theme() ) {
       
   843 		$classes[] = 'wp-child-theme-' . sanitize_html_class( get_stylesheet() );
   837 	}
   844 	}
   838 
   845 
   839 	if ( ! empty( $css_class ) ) {
   846 	if ( ! empty( $css_class ) ) {
   840 		if ( ! is_array( $css_class ) ) {
   847 		if ( ! is_array( $css_class ) ) {
   841 			$css_class = preg_split( '#\s+#', $css_class );
   848 			$css_class = preg_split( '#\s+#', $css_class );
  1765  *
  1772  *
  1766  * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
  1773  * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
  1767  * @return string HTML content for password form for password protected post.
  1774  * @return string HTML content for password form for password protected post.
  1768  */
  1775  */
  1769 function get_the_password_form( $post = 0 ) {
  1776 function get_the_password_form( $post = 0 ) {
  1770 	$post   = get_post( $post );
  1777 	$post                  = get_post( $post );
  1771 	$label  = 'pwbox-' . ( empty( $post->ID ) ? rand() : $post->ID );
  1778 	$field_id              = 'pwbox-' . ( empty( $post->ID ) ? wp_rand() : $post->ID );
  1772 	$output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post">
  1779 	$invalid_password      = '';
       
  1780 	$invalid_password_html = '';
       
  1781 	$aria                  = '';
       
  1782 	$class                 = '';
       
  1783 	$redirect_field        = '';
       
  1784 
       
  1785 	// If the referrer is the same as the current request, the user has entered an invalid password.
       
  1786 	if ( ! empty( $post->ID ) && wp_get_raw_referer() === get_permalink( $post->ID ) && isset( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ) ) {
       
  1787 		/**
       
  1788 		 * Filters the invalid password message shown on password-protected posts.
       
  1789 		 * The filter is only applied if the post is password protected.
       
  1790 		 *
       
  1791 		 * @since 6.8.0
       
  1792 		 *
       
  1793 		 * @param string  $text The message shown to users when entering an invalid password.
       
  1794 		 * @param WP_Post $post Post object.
       
  1795 		 */
       
  1796 		$invalid_password      = apply_filters( 'the_password_form_incorrect_password', __( 'Invalid password.' ), $post );
       
  1797 		$invalid_password_html = '<div class="post-password-form-invalid-password" role="alert"><p id="error-' . $field_id . '">' . $invalid_password . '</p></div>';
       
  1798 		$aria                  = ' aria-describedby="error-' . $field_id . '"';
       
  1799 		$class                 = ' password-form-error';
       
  1800 	}
       
  1801 
       
  1802 	if ( ! empty( $post->ID ) ) {
       
  1803 		$redirect_field = sprintf(
       
  1804 			'<input type="hidden" name="redirect_to" value="%s" />',
       
  1805 			esc_attr( get_permalink( $post->ID ) )
       
  1806 		);
       
  1807 	}
       
  1808 
       
  1809 	$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 . '
  1773 	<p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p>
  1810 	<p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p>
  1774 	<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>
  1811 	<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>
  1775 	';
  1812 	';
  1776 
  1813 
  1777 	/**
  1814 	/**
  1778 	 * Filters the HTML output for the protected post password form.
  1815 	 * Filters the HTML output for the protected post password form.
  1779 	 *
  1816 	 *
  1780 	 * If modifying the password field, please note that the core database schema
  1817 	 * If modifying the password field, please note that the WordPress database schema
  1781 	 * limits the password field to 20 characters regardless of the value of the
  1818 	 * limits the password field to 255 characters regardless of the value of the
  1782 	 * size attribute in the form input.
  1819 	 * `minlength` or `maxlength` attributes or other validation that may be added to
       
  1820 	 * the input.
  1783 	 *
  1821 	 *
  1784 	 * @since 2.7.0
  1822 	 * @since 2.7.0
  1785 	 * @since 5.8.0 Added the `$post` parameter.
  1823 	 * @since 5.8.0 Added the `$post` parameter.
  1786 	 *
  1824 	 * @since 6.8.0 Added the `$invalid_password` parameter.
  1787 	 * @param string  $output The password form HTML output.
  1825 	 *
  1788 	 * @param WP_Post $post   Post object.
  1826 	 * @param string  $output           The password form HTML output.
  1789 	 */
  1827 	 * @param WP_Post $post             Post object.
  1790 	return apply_filters( 'the_password_form', $output, $post );
  1828 	 * @param string  $invalid_password The invalid password message.
       
  1829 	 */
       
  1830 	return apply_filters( 'the_password_form', $output, $post, $invalid_password );
  1791 }
  1831 }
  1792 
  1832 
  1793 /**
  1833 /**
  1794  * Determines whether the current post uses a page template.
  1834  * Determines whether the current post uses a page template.
  1795  *
  1835  *