Created
January 5, 2019 08:52
-
-
Save Tsunamijaan/1e6b3ccfb5cc16a6fbe98424f4bd3693 to your computer and use it in GitHub Desktop.
Member only content
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
| add_shortcode( 'member', 'member_check_shortcode' ); | |
| function member_check_shortcode( $atts, $content = null ) { | |
| if ( is_user_logged_in() && !is_null( $content ) && !is_feed() ) | |
| return $content; | |
| return ''; | |
| } | |
| Uses:=============== | |
| [member] | |
| This text will be only displayed to registered users. | |
| [/member] | |
| Require login to view specifics posts in wordpress | |
| function you_must_login() { | |
| global $post; | |
| if ( !is_single() ) // Use: !is_single() for members only posts and, Use: !is_page() for members only pages. | |
| return; | |
| $post_ids = array( 188, 185, 171 ); // array of post IDs that force users to login before reading | |
| if ( in_array( (int) $post->ID, $post_ids ) && !is_user_logged_in() ) { | |
| auth_redirect(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment