Skip to content

Instantly share code, notes, and snippets.

@bonny
Created June 13, 2013 08:15
Show Gist options
  • Save bonny/5772054 to your computer and use it in GitHub Desktop.
Save bonny/5772054 to your computer and use it in GitHub Desktop.
WordPress function that uses filter "get_pages" to add argument "exclude_password_protected=1" Adding that argument will exclude password protected pages from for example wp_list_pages. If a user has entered correct password then the page will be visible.
<?php
// modify get_pages so we can add "exclude_password_protected=1" to exclude password protected
// pages from for example wp_list_pages
// if user has entered correct password then the page will be visible
function ep_exclude_password_protected_pages($pages, $r) {
if ( isset( $r["exclude_password_protected"] ) && $r["exclude_password_protected"] ) {
for ($i = 0; $i < sizeof($pages); $i++) {
if ( post_password_required($pages[$i]) ) {
unset( $pages[$i] );
}
}
}
return $pages;
}
add_filter("get_pages", "ep_exclude_password_protected_pages", 10, 2);
@carasmo
Copy link

carasmo commented Jun 8, 2016

Thank you so much for this. Works wonderfully. I just remove the conditional because my client doesn't want to ever have password protected pages in any list of pages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment