Home Support Extensions Memberships Membership restriction attributes AND pages

Membership restriction attributes AND pages

  • Author
    Posts
  • elioberga

    Hi ihor,
    in hivepress settings I can decide wether to restrict an attribute (that I choose in the plan page) or the single listing page. I can’t select both? I need to restrict just some attributes AND just some other random pages I create (not the listing pages), why there is not the possibility to select both?

    Thanks.

    ihor developer

    Since it’s a HivePress extension it restricts access to HivePress content (listings, vendors and features of other extensions like Reviews or Messages), but there’s a PHP snippet that you can use to restrict access to regular WordPress pages:

    add_action(
    	'template_redirect',
    	function() {
    		if ( current_user_can( 'edit_others_posts' ) || ! function_exists( 'hivepress' ) ) {
    			return;
    		}
    
    		if ( is_page( [ 'one', 'two', 'three' ] ) && ! hivepress()->request->get_context( 'membership' ) ) {
    			wp_safe_redirect( hivepress()->router->get_url( 'membership_plans_view_page' ) );
    
    			exit;
    		}
    	}
    );

    Replace “one”, “two”, “three” with page slugs.

    elioberga

    Thank ihor.
    this snippet should be valid for any membership plan, is it? how can I restrict just to one plan?
    It should be something like:

    if ( current_user_can( ‘HAVE MEMBERSHIP PREMIUM’ )

    what should be written instead of HAVE MEMBERSHIP PREMIUM?

    Thanks

    elioberga

    I tried but an external user not even logged in can still enter the page..

    ihor developer

    Yes, it works if any membership is purchased, membership-specific restrictions for pages would require advanced customizations. Please make sure that you set the correct page slugs, I’ve just tested it with “sample-page” (the default WordPress page) and it redirects me back to the home page if I don’t have a membership.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.