Created
June 13, 2013 08:15
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.