WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Feature Request: Post or page if password protected (5 posts)

  1. cobraeyes
    Member
    Posted 1 year ago #

    Hi,

    i have a feature request. Not sure if this is the way to go about it but anyway here it is.
    I'd like the translation to differ between post and pages when you password protect it.
    Today it says:
    This post is password protected. To view it please enter your password below:

    Would like it to differ on post and pages. For example:
    This post is password protected. To view it please enter your password below:
    This page is password protected. To view it please enter your password below:

    Best regards,
    Marcus

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    That could be dealt with via your theme.

  3. cobraeyes
    Member
    Posted 1 year ago #

    ok, via the page/post template?

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    No - via your theme's functions.php file and the the_password_form filter. Something like:

    function my_password_form() {
    	global $post;
    	if(is_page() ) $post_or_page = 'page';
    	else $post_or_page = 'post';
    	$label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
    	$output = '<div class="password-form"><p class="protected-text">';
    	 $output .= sprintf( __('This %1$s is password protected. To view it, please enter your password below:'), $post_or_page);
    	$output .= '</p><form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
    	<p><label for="' . $label . '">' . __('Password:') . ' </label> <input name="post_password" id="' . $label . '" type="password" size="20" /> <input type="submit" name="Submit" value="' . esc_attr__('Submit') . '" /></p></form></div>';
    	return $output;
    }
    add_filter('the_password_form','my_password_form');

    should work.

  5. cobraeyes
    Member
    Posted 1 year ago #

    Thx alot! worked like a charm! ;)

Topic Closed

This topic has been closed to new replies.

About this Topic