Created
May 14, 2014 02:52
-
-
Save sscovil/535de15f134be519f6e4 to your computer and use it in GitHub Desktop.
WordPress function to use with WP-Members plugin. Replaces the post index with a login page. To use, create a page and add the shortcode `[wp-members page="login"] ` to it, then get the ID of that page and put it on line 7 as the value of `page_id`.
This file contains 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 | |
//* Replace post index with login page for non-members | |
function premium_posts_05132014sms( $query ) { | |
if ( $query->is_home() && $query->is_main_query() ) { | |
if ( current_user_can( 'subscriber' ) || !is_user_logged_in() ) { | |
$query->set( 'page_id', '12' ); // Replace 12 with the ID of your login page | |
$query->set( 'post_type', 'page' ); | |
} | |
} | |
} | |
add_action( 'pre_get_posts', 'premium_posts_05132014sms', 9999 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment