Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support password protected posts #51

Merged
merged 2 commits into from
Sep 26, 2023

Conversation

dustin-jw
Copy link
Contributor

Description

This work adds the required logic and templates to support password protected posts and pages. The newly established pattern is to use the render_with_password_protection function on any single post page, which will render the single-password.twig template if a password is required. For listing pages, a filter was added to set has_password to true for non-admin queries.

Closes #48

To Validate

  1. Make sure all PR Checks have passed
  2. Pull down this branch
  3. Run npm start
  4. Add enough varied test posts to validate when they are or aren't being shown in listing pages
  5. In the WordPress editor for one or more posts, set the visibility to "Password protected", and publish the post
  6. View the post and confirm that you need to enter a password to see the page
  7. Do the same for a Page, such as the "Sample page" that's added when you first initialize WordPress
  8. Check the listing pages to make sure the password protected posts aren't shown, including:
    1. The home page
    2. The search page (?s=search+term)
    3. Category pages (?cat=1)
  9. Change the password protected posts to be "Public" and confirm that they don't require passwords on the pages themselves and that they are shown in listing pages

$page_num = empty( $page_num ) ? 1 : $page_num;
$posts_per_page = 12;
$count = $GLOBALS['wp_query']->post_count;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing these wasn't strictly necessary, but these variables weren't used anywhere from what I could tell.

@dustin-jw dustin-jw force-pushed the feat--password-protected-posts branch from 71883c3 to 2499706 Compare September 25, 2023 18:18
Copy link
Contributor

@rise-erpelding rise-erpelding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great! I can set a password on a post and not be able to see it in the listing/search for it, if given the url I can't see the content without the correct password, and removing this setting also works as expected (and vice versa). 🏆

@dustin-jw dustin-jw force-pushed the feat--password-protected-posts branch from 2499706 to c3ee959 Compare September 26, 2023 14:11
@dustin-jw dustin-jw merged commit c3ee959 into main Sep 26, 2023
1 check passed
@dustin-jw dustin-jw deleted the feat--password-protected-posts branch September 26, 2023 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support password protected posts
2 participants