Somebody using the Image store plugin asked me, how can I allow a user to access password-protected galleries (posts) without having the user login every time and to every single gallery.
There are a few solutions out there that requires to modify WordPress core files, this is not recommended because you will not be able to update WordPress or you will have to remember to make the change every time you update.
This solution works with WordPress’ API and you can use it for posts or pages not just the galleries created by the Image Store plugin. Add this code in your functions.php file.
function bypass_password_protected_posts( $post ){ //make sure it a single post if( !is_singular() ) return; global $wp_query, $user_ID; if( $wp_query->queried_object->ID == $post->ID ){ if( current_user_can('administrator' ) ) {// change capability to fit your needs $post->post_password = false; wp_cache_set( $post->ID, $post, 'posts' ); } } } add_action('the_post','bypass_password_protected_posts',100);
Change “is_singular()” to “is_single()” for posts or “is_page()” for pages. For a more spefic post, page or custom post type view WordPress’ condition tags page.
Comments
One response to “Bypass WordPress password protected posts”
I really like your blog.. very nice colors & theme. Did you design this website yourself or did you hire someone to do it for you? Plz reply as I’m looking to construct my own blog and would like to know where u got this from. thanks