Advertisement
Guest User

FT_Password_Protect_Children_Pages (Modified)

a guest
Sep 1st, 2010
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.14 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @package
  4.  * @author FullThrottleDevelopment.com
  5.  * @version 0.2
  6.  * http://wordpress.org/extend/plugins/ft-password-protect-children-pages/
  7.  */
  8. /*
  9. Plugin Name: FT Password Protect Children Pages (Modified by Merimac http://www.maisdisdonc.com/)
  10. Plugin URI: http://fullthrottledevelopment.com/password-protect-children-pages
  11. Description: This plugin does one thing. If a page that is password protected has children pages, all children pages will be protected with the same password. If the correct password is entered on the parent page or any of its children pages, all related pages will be viewable to the user.
  12. Author: FullThrottle Development
  13. Version: 0.2
  14. Author URI: http://fullthrottledevelopment.com/
  15. Primary Developer: Glenn Ansley (glenn@glennansley.com)
  16. */
  17.  
  18. // This function prints the password form if the parent page is password protected. It is called whenever 'the_content' is invoked.
  19. function ft_password_protect_children_page_contents( $org_content ){
  20.     if ( is_page() ){
  21.         global $post;
  22.  
  23.         $ancestors = $post->ancestors;
  24.        
  25.         if ( !empty( $ancestors) ){
  26.             foreach ($ancestors as $ancestor){
  27.                 if ( post_password_required( $ancestor ) ) {
  28.                     $real_post = $post;
  29.                     $post = $ancestor;
  30.                
  31.                     echo get_the_password_form();
  32.                     $post = $real_post;
  33.                     return;
  34.                 }
  35.             }
  36.         }
  37.     }
  38.     return $org_content;
  39. }
  40. add_filter( 'the_content', 'ft_password_protect_children_page_contents' );
  41.  
  42. // This function prints the "excerpt can't be displayed" message if the parent post is protected. It is called whenever 'get_the_excerpt' is invoked (which gets invoked by get_excerpt() ).
  43. function ft_password_protect_children_page_excerpts( $org_excerpt ){
  44.     if ( is_page() ){
  45.         global $post;
  46.        
  47.         $ancestors = $post->ancestors;
  48.  
  49.         if ( !empty( $ancestors ) ){
  50.             foreach ($ancestors as $ancestor){
  51.                 if ( post_password_required( $ancestor ) ) {
  52.                     $output = wpautop( __('There is no excerpt because this is a protected post.') );
  53.                     return $output;
  54.                 }
  55.             }
  56.         }
  57.     }
  58.     return $org_excerpt;
  59. }
  60. add_filter( 'get_the_excerpt', 'ft_password_protect_children_page_excerpts' , 9);
  61.  
  62. // This function alter's the Post Title to include the protected_title_format
  63. function ft_password_protect_children_page_titles( $org_title, $title_id='' ){
  64.     if ( is_page() && in_the_loop() ){
  65.    
  66.         global $post;
  67.        
  68.         $ancestors = $post->ancestors;
  69.         $ancestors_post = get_post( $ancestors );
  70.        
  71.         if ( !empty( $ancestors ) ){
  72.             foreach ($ancestors as $ancestor){
  73.                 if ( post_password_required( $ancestor ) || isset( $ancestor_post->post_password ) ) {
  74.  
  75.                     $protected_title_format = apply_filters( 'protected_title_format', __('Protected: %s') );
  76.                     $title = sprintf( $protected_title_format, $org_title );
  77.                     return $title;
  78.                 }
  79.             }
  80.         }
  81.     }
  82.     return $org_title;
  83. }
  84. add_filter( 'the_title', 'ft_password_protect_children_page_titles', 10 , 2 );
  85. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement