• Resolved TheMusik

    (@themusik)


    I’m trying to figure out the best way to do this. I have a site that has restricted access to videos. The problem is, is that the video image on the main video portfolio page disappears when I add restrictions to it. This makes it look like there are no videos to watch because when you are not logged in, you cannot even see the videos available for purchase.

    So my resolve for this situation was to create previews of each video as their own item I could restrict. Except, this time I need to restrict the members from seeing these. So that way when you are not logged in, you can see Only the previews listed but then when you are logged in you see Only the full videos listed.

    But I can’t figure out how this can work since I don’t know how to make a group for people that haven’t had one assigned to their profile when signing up? Is there a way to target viewers not logged in?

    Any help on this would be greatly appreciated.

    https://wordpress.org/plugins/groups/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter TheMusik

    (@themusik)

    I know there is [groups_non_member] for specific content but what about an entire post type? I’ve seen this question asked quite a few times already with no answers. Would it not be possible to have a built in group for [groups_non_member] since the shortcode is basically doing the same thing? What would be the best way to go about this?

    Plugin Author itthinx

    (@itthinx)

    You can handle this using a specific template for the post type. See the API documentation please.

    Thread Starter TheMusik

    (@themusik)

    I have looked through the API. I’m not that proficient with php. I’ve tried a few ways to implement it but I’m getting errors each time. Would I be adding this to the class-groups-post-access.php file? Is there any way you could provide an example?

    Thanks

    Thread Starter TheMusik

    (@themusik)

    Could you give me a heads up on which section of code I need to make the changes to from the API? Or Which .php file I should add the template to? Im not real sure what you mean by template also.

    Thread Starter TheMusik

    (@themusik)

    In the class-groups-post-access.php I have the code

    /**
    	 * Filter posts by access capability.
    	 *
    	 * @param array $posts list of posts
    	 * @param WP_Query $query
    	 */
    	public static function the_posts( $posts, &$query ) {
    		$result = array();
    		$user_id = get_current_user_id();
    		foreach ( $posts as $post ) {
    			if ( self::user_can_read_post( $post->ID, $user_id ) ) {
    				$result[] = $post;
    			}
    		}
    		return $result;
    	}

    My theme is using this to call the custom thumbnail:

    //project style 2
        else if($project_style == '2') { ?>
    
            <div class="work-item style-2">
    
                <?php
                    $thumb_size = (!empty($masonry_item_sizing)) ? $masonry_item_sizing : 'portfolio-thumb';
    
                    //custom thumbnail
                    $custom_thumbnail = get_post_meta($post->ID, '_nectar_portfolio_custom_thumbnail', true); 
    
                        if( !empty($custom_thumbnail) ){
                            echo '<img class="custom-thumbnail" src="'.$custom_thumbnail.'" alt="'. get_the_title() .'" />';
                        }
                        else {
    
                            if ( has_post_thumbnail() ) {
                                 echo get_the_post_thumbnail($post->ID, $thumb_size, array('title' => ''));
                            } 
    
                            //no image added
                            else {
                                switch($thumb_size) {
                                    case 'wide':
                                        $no_image_size = 'no-portfolio-item-wide.jpg';
                                        break;
                                    case 'tall':
                                        $no_image_size = 'no-portfolio-item-tall.jpg';
                                        break;
                                    case 'regular':
                                        $no_image_size = 'no-portfolio-item-tiny.jpg';
                                        break;
                                    case 'wide_tall':
                                        $no_image_size = 'no-portfolio-item-tiny.jpg';
                                        break;
                                    default:
                                        $no_image_size = 'no-portfolio-item-small.jpg';
                                        break;
                                }
                                 echo '<img src="'.get_template_directory_uri().'/img/'.$no_image_size.'" alt="no image added yet." />';
                            }   
    
                    } ?>

    Would I add an else statement? or would I have to create a completely new public static function ?

    I also saw this for featured image in the Class-Groups-Post-Access.php:
    add_filter( "show_featured_img", array(__CLASS__, "show_featured_img" ), 1 );

    Could I tie this in somehow with the $custom_thumbnail?

    Thread Starter TheMusik

    (@themusik)

    Instead of editing the plugin, it was pointed out to me that I could alter this with wordpress alone.

    For Anyone that wants to hide specific things whether posts or categories from groups and show them to guests. You can do it by simply using if_user_is_logged_in.
    I decided to put mine in a plugin so I needed to use the pre_get_posts. This allowed me to just create a preview category and hide it all together from all members logged in.

    function exclude_category( $query ) {
    if ( is_user_logged_in() ) {
    $query->set( ‘cat’, ‘-Preview’);
    }else {
    $query->set( ‘cat’, ‘Preview’);
    }
    }
    add_action( ‘pre_get_posts’, ‘exclude_category’ );

    Thread Starter TheMusik

    (@themusik)

    The code above didn’t work for me actually in the end. If anyone is interested in how to achieve this it usually can be done by manipulating wordpress for the opposite of what the plugin is doing.

    In my case I just added an extra portfolio one with previews and the other excluding the previews category. I then added the previews portfolio to my main menu by doing a custom link. I selected the css class screen option and added the class logged-in-nav to the preview menu link.

    Then I added this css to my theme to hide the previews from logged in users

    .your-nav-name li.logged-in-nav {
      display: list-item;
    } 
    
    body.logged-in .your-nav-name li.logged-in-nav {
      display: none;
    }

    Change out your-nav-name with whatever your menu name is in your source code.
    Then all I did was secure my portfolio section with the groups plugin so the nav link doesn’t show to non-logged in users. So users not logged in see the Previews link and do not the other one and logged in see the opposite.

    This is just an example of the logic on how you can restrict from logged in users through wordpress.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to restrict content from only logged in members’ is closed to new replies.